Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImageWriteToSavedPhotosAlbum saves to wrong size and quality

Tags:

iphone

I'm trying to take a screen shot of my app's current view and save it to photo album (to then be emailed or MMS'ed).

UIGraphicsBeginImageContext(self.view.bounds.size); 

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(viewImage, self, @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);

This works but the resulting image apears to be larger (533x800px) and heavily compressed when I email it from the photo library.

I've tried first writing the UIImage to file and then saving to album but still get the same issue.

If I used the in-built screenshot functionality on the iPhone the view saves correctly to photo album at 320x480 but the above code appears to save a larger image for some reason?

Thanks!

like image 636
wuwongy Avatar asked Sep 04 '09 13:09

wuwongy


2 Answers

I found a decent workaround, which is to essentially rewrap the UIImage as a PNG, then save the rewrapped version. Code looks something like this:

UIImage* im = [UIImage imageWithCGImage:myCGRef]; // make image from CGRef
NSData* imdata =  UIImagePNGRepresentation ( im ); // get PNG representation
UIImage* im2 = [UIImage imageWithData:imdata]; // wrap UIImage around PNG representation
UIImageWriteToSavedPhotosAlbum(im2, nil, nil, nil); // save to photo album
like image 103
Ben Weiss Avatar answered Oct 14 '22 12:10

Ben Weiss


I had that same error, on my part, that was solved when I rounded the decimal points to be the same scale as the iPhone, try it, make sure the scale is 1.0, 2.0, etc and not 3.1, that will throw it off.

like image 1
Jaime Enriquez Avatar answered Oct 14 '22 11:10

Jaime Enriquez