如何在iOS中将UIImage转换为J2K(JPEG2000)?

我已经设法让OpenJPEG在我的iOS应用程序中编译,但我不知道从哪里开始尝试将UIImage转换为J2K文件或J2K内存缓冲区。 build议?

显然ImageIO可以做到这一点。 你需要添加图像io框架到你的项目,然后这个代码为我工作:

#import <ImageIO/ImageIO.h> // or @import ImageIO if modules enabled #import <MobileCoreServices/MobileCoreServices.h> // ... // quality is 0-1 (0 = smallest file size, 1 = lossless quality) + (NSData*) convertToJPEG2000:(UIImage*)image withQuality:(float)quality { NSMutableData* d = [NSMutableData data]; CGImageDestinationRef destinationRef = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)d, kUTTypeJPEG2000, 1, NULL); CGImageDestinationSetProperties(destinationRef, NULL); CGImageDestinationAddImage(destinationRef, image.CGImage, (__bridge CFDictionaryRef)@{ (NSString*)kCGImageDestinationLossyCompressionQuality: @(quality) }); if (!CGImageDestinationFinalize(destinationRef)) { d = nil; } CFRelease(destinationRef); return d; }