UIGraphicsGetImageFromCurrentImageContext gives poor quality / low resolution image, how do I get better?
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 :-)
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?
精彩评论