在Objective-C中将字节数组编码为JPEG图像 [英] Encode Byte array to JPEG image in Objective-C

查看:88
本文介绍了在Objective-C中将字节数组编码为JPEG图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个原始数据文件,即图像数据。现在,我需要在Objective-C中将Raw数据转换为JPEG图像。
步骤:

I have a file of raw data , its a image data. Now i need to convert the Raw data to JPEG image in Objective-C. STEPS:

1)将包含原始数据的文件读入NSString。
2)将字符串编码为JPEG编码器
3)创建JPEG图像

1) Read the file containing the raw data into NSString. 2) Encode the string to JPEG encoder 3) Create an JPEG image

您能指导我如何实现吗?

Can you please guide me how to achieve this?

iPhone OS中是否有可用的库可以编码为JPEG。

Is there any library available in iPhone OS to encode into JPEG.

推荐答案

这是从JPEG数据创建 UIImage 的方式:

This is how you create a UIImage from JPEG data:

UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfFile:…]];

这就是创建 UIImage

NSData *data = UIImageJPEGRepresentation(anImage, compressionQuality);

...但是仅在写完之后,我才意识到您可能想从原始图像样本数据创建JPEG图像?在这种情况下,您可能必须创建具有正确图像样本格式的 CGImage 并使用提供程序提供位图数据,请参见 CGImageCreate 。 (希望有人可以纠正我或提供示例代码。)然后您可以轻松地从 CGImage 创建一个 UIImage 并使用上面的代码。

…but only after writing this I realized you probably want to create a JPEG image from raw image sample data? In that case you’ll probably have to create a CGImage with the correct image sample format and supply the bitmap data using a provider, see CGImageCreate. (Hopefully somebody can correct me or come up with sample code.) Then you can easily create an UIImage from the CGImage and use the code above.

这篇关于在Objective-C中将字节数组编码为JPEG图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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