如何在iOS中将UIImage转换为J2K(JPEG2000)? [英] How do I convert UIImage to J2K (JPEG2000) in iOS?

查看:230
本文介绍了如何在iOS中将UIImage转换为J2K(JPEG2000)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have managed to get OpenJPEG to compile in my iOS app, but I have no clue where to begin trying to convert a UIImage to a J2K file or J2K in memory buffer. Suggestions?

推荐答案

显然ImageIO可以做到这一点。你需要在你的项目中添加image io框架,然后这段代码对我有用:

Apparently ImageIO can do this. You'll need to add image io framework to your project and then this code is working for me:

#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;
}

这篇关于如何在iOS中将UIImage转换为J2K(JPEG2000)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆