Dear scientists, I use the following code to capture the screen and save it in jpg inside the photo album. Which works great.
However, when working on an iPhone 4 with a higher resolution, the captured screen is only 320X480 versus higher resolution (I assume this also applies to the iPad).
How can I solve these problems?
- (IBAction)saveAsJPG
{
UIImage *image = [self captureView:self.view];
UIImageWriteToSavedPhotosAlbum(image, self,
@selector(image:didFinishSavingWithError:contextInfo:), nil);
}
-(UIImage *)captureView:(UIView *)view
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
[view.layer renderInContext:ctx];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
chewy source
share