Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MacccUser

macrumors newbie
Original poster
Mar 19, 2014
3
0
I can't solve this problem. Load image, convert to CGImageRef. Try to get bitmap context and render on the screen.

Code:
NSURL *imageFileURL = [NSURL fileURLWithPath:stringIMG];

   CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)imageFileURL, NULL);
   CGImageRef imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);

    NSInteger bitsPerComponent = CGImageGetBitsPerComponent(imageRef);
    NSInteger bitsPerPixel = CGImageGetBitsPerPixel(imageRef);
    CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
    NSInteger bytesPerRow = CGImageGetBytesPerRow(imageRef);
    NSInteger width = CGImageGetWidth(imageRef);
    NSInteger height = CGImageGetHeight(imageRef);
    CGColorSpaceRef colorspace = CGImageGetColorSpace(imageRef);

    size_t rawData = bytesPerRow*height;
    unsigned char *data = malloc(rawData);
    memset(data2, 0, rawData);

     CGContextRef context = CGBitmapContextCreate(data, width, height, bitsPerComponent, bytesPerRow, colorspace, bitmapInfo);


    CGImageRef imageRef2 = CGBitmapContextCreateImage(context);

   // CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef2);
    UIImage *result = [UIImage imageWithCGImage:imageRef2];//if i do like this i got white empty screen

    UIImageView *image = [[UIImageView alloc] initWithImage:result];
    [self.view addSubview:image];// if i do like this i got black rectangle on the white screen
I have no idea. I check by breakpoint that context is not null. I don't know what should i do. Please maybe anyone can help me?
 
What is your goal? Why do you want a bitmap context?

Most of the code you show can easily be replaced with [UIImage imageWithContentsOfFile:]
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.