views:

338

answers:

1

Ok so I am taking a screen shot of a photo I took with my camera on the iPhone. I put the camera photo into UIImageView and grab a screenshot of it using this sort of code (this is from http://www.skylarcantu.com/blog/2009/10/16/saving-a-view-as-an-image/)...

 - (void)takeScreenshot {

    UIWindow *theScreen = [[UIApplication sharedApplication].windows objectAtIndex:0];     
    UIGraphicsBeginImageContext(theScreen.frame.size);  
    [[theScreen layer] renderInContext:UIGraphicsGetCurrentContext()];   
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();              
    [self doSomethingWith:screenshot]; 
}

I have it working as I want but the image quality of the screenshot is much worse than the image I take with my camera. Is there a way to overcome this? I guess it is because this takes a screenshot which captures the resolution of the iPhone screen rather than the resolution of the camera - maybe?!

Any suggestions would be great :-)

+1  A: 

You're exactly right. The resolution of the screen (320 x 480) is much less than the camera (1200 x 1600 on 3G, 1536 x 2048 on the 3GS) so your UIImageView must be 320x480, and it automatically downsamples your image to fit. This seems convoluted, though -- you already have the photo as a UIImage at the higher resolution -- are you trying to overlay things onto it or something?

Andy Milburn
Yeah that's exactly right, can i overlay something without loosing the resolution?
No, I'm afraid it'll be more complicated. You'll have to call UIGraphicsBeginImageContext() with the size of your original camera image, do the drawAtPoint therein, and then draw other things into that same context. Then ultimately you'll call UIGraphicsGetImageFromCurrentImageContext() to get a new, composite image.
Andy Milburn
Ok well thanks for the heads up, I'll look into that. These things are never as easy as I think they will be!