【发布时间】:2013-07-09 19:25:11
【问题描述】:
我正在尝试弄清楚如何将 CGImageRef 保存为 JPEG2000。
目前我得到了散乱的图像输出。
我有以下代码适用于除 kUTTypeJPEG2000 之外的所有其他格式。保存为 kUTTypeGIF 或 kUTTypePNG 可以正常工作。有趣的是,保存为不带 alpha 通道的 kUTTypeJPEG2000 也可以。
我怎样才能让图像正确输出?
- (void)saveImage:(CGImageRef)image path:(NSString *)path
{
// Set the image compression quality
CFMutableDictionaryRef properties = CFDictionaryCreateMutable(nil,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
// Save and finalize
CFURLRef url = CFBridgingRetain([[NSURL alloc] initFileURLWithPath:path]);
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypeJPEG2000, 1, NULL);
CGImageDestinationAddImage(destination, image, properties);
CGImageDestinationFinalize(destination);
CFRelease(url);
}
【问题讨论】: