开发者

Why I don't get a CGContextRef

I try to get a CGContextRef from UIImage. Always my CGContextRef is 0x0 in Debugger.

Here is the co开发者_JAVA技巧de:

NSString *movName = imgName;
        NSString *path = [[NSBundle mainBundle] pathForResource:movName ofType:@"png"];
        UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];

        CGImageRef imageRef = [image CGImage];
        CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
        CGColorSpaceRef colorSpaceInfo = CGImageGetColorSpace(imageRef);

        CGContextRef bitmap = CGBitmapContextCreate(NULL, 
                                                    100, 
                                                    100, 
                                                    CGImageGetBitsPerComponent(imageRef), 
                                                    CGImageGetBytesPerRow(imageRef), 
                                                    colorSpaceInfo, 
                                                    bitmapInfo);

thank you for answering


The NULL result is detailed in the documentation:

Return Value:
A new bitmap context, or NULL if a context could not be created

I would start by investigating the parameters you are passing to the function. It is possible the source image isn't being loaded properly. Have you tried debugging this code? What does the debugger tell you?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜