Flying_Banana
Flying_Banana

Reputation: 2910

Better quality image from UIGraphicsGetImageFromCurrentImageContext()

I'm currently using UIGraphicsGetImageFromCurrentImageContext() to save a content's image to a user's camera roll, but the image quality is worse than if I do a screen shot in the simulator. Is there any way to improve it? And what format the saved image is in anyway? Bmp? Is there any way to change this?

Here's my save code:

CGSize size = [content bounds].size;
UIGraphicsBeginImageContext(size);
[[content layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *originalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(originalImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

Upvotes: 14

Views: 7598

Answers (2)

Wain
Wain

Reputation: 119031

Instead of using UIGraphicsBeginImageContext you should be using:

UIGraphicsBeginImageContextWithOptions(size, NO, 0);

Upvotes: 51

Tom
Tom

Reputation: 1349

If you're on retina display the size of the context is only half the size of the "real" image.

Try to double the size (or to be correct use the contentScaleFactor of the view).

Upvotes: 0

Related Questions