2

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 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you so much for the reply. I'm looking into CGImageCreate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.