CGImageDestinationCreateWithData没有创建CGImageDestinationRef对象

时间:2012-07-03 08:40:20

标签: iphone objective-c ios automatic-ref-counting core-foundation

我确信这很简单,但我找不到它。

我正在尝试使用CGImageDestinationRef函数创建一个CGImageDestinationCreateWithData,但它返回给我一个零。

功能文档:

http://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGImageDestination/Reference/reference.html#//apple_ref/c/func/CGImageDestinationCreateWithData

这个功能很简单,但我似乎无法让它给我一个对象。我在ARC课程中,因此函数周围有一个桥接包装器。

我的代码段:

NSMutableData *data = [[NSMutableData alloc] init];
CGImageDestinationRef imageDestination = nil;

imageDestination = (__bridge CGImageDestinationRef) CFBridgingRelease(CGImageDestinationCreateWithData ((__bridge CFMutableDataRef)data, (__bridge CFStringRef)type, 1, NULL));

if (!imageDestination)
    NSLog(@"This is always called. :-(");

如果有人发现我做了些蠢事,我会非常感激!

1 个答案:

答案 0 :(得分:3)

我已经解决了这个问题并在这里发布了答案,因为它可能在将来帮助其他人。

我的类型设置为@“image / jpg”,这似乎不起作用(文档建议它应该)。

当我将类型更改为@“public.jpeg”时,该函数开始按预期工作。

在下面的评论中使用Jim的提示,这就是我最终要从URL中找到正确的UTI类型:

NSString *uti = CFBridgingRelease(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef)[NSString stringWithFormat:@"image/%@", url.pathExtension], kUTTypeImage));

相关问题