Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: writing a CGImageRef disk in png or jpeg

Tags:

ios

uikit

What is the best way to save CGImageRef to a png or jpeg file in iOS?

For a general cocoa application (not using UIkit), see: Saving CGImageRef to a png file? but this seems too long and clunky.

like image 442
Guy Avatar asked Feb 12 '13 11:02

Guy


1 Answers

Using UIKit, the code becomes a simple 3-liner:

UIImage *uiImage = [UIImage imageWithCGImage:cgImage];
NSData *jpgData = UIImageJPEGRepresentation(uiImage, 0.9f);
[jpgData writeToFile:path atomically:NO];
like image 180
Guy Avatar answered Sep 28 '22 12:09

Guy