Encode Byte array to JPEG image in Objective-C
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 l开发者_C百科ibrary available in iPhone OS to encode into JPEG.
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.
精彩评论