tags:

views:

395

answers:

4

Hi,

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!

A: 

This issue exists since the iPhone SDK first version is available. But Apple don't take care about, no answers in discussion forums, absolutely nothing. This only happens on iPod Touch. My iPod customers are very angry about that. Thanks for 1 star bad reviews powerd by Apple! :-(((

Someone
A: 

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.

Jaime Enriquez
A: 

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
Ben Weiss
A: 

@Ben Weiss. I have tried your method but it does not work. =(