Software screen capture on Retina / High res grids

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?

// Save the captured image to photo album
- (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; 
}
+3
source share
1 answer

Use UIGraphicsBeginImageContextWithOptionsinstead UIGraphicsBeginImageContext:

UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, 0.0);

See Apple QA1703 for details .

+15
source

Source: https://habr.com/ru/post/1782168/


All Articles