Encode Byte array to JPEG image in Objective-C

心已入冬 提交于 2019-12-24 00:00:51

问题


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) 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?

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


回答1:


This is how you create a UIImage from JPEG data:

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

And this is how you create a JPEG representation of a UIImage:

NSData *data = UIImageJPEGRepresentation(anImage, compressionQuality);

…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.



来源:https://stackoverflow.com/questions/5325084/encode-byte-array-to-jpeg-image-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!