UIGraphicsGetImageFromCurrentImageContext retina resolution?

UIImageView *cellimage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0 , 107, 70)];

The above operator, I’m sure, will make the appropriate sizes both in devices for retina resolution and in standard ones. This is a frame measuring 107 x 70 pixels on the standard and 214 x 140 on the retina.

What I want to know is what UIGraphicsGetImageFromCurrentImageContextdoes the same thing below .. will the image be 67 x 67 for standard and 124 x 124 for retina versions?

    CGSize imagesize = CGSizeMake(67, 67);
        UIGraphicsBeginImageContext(imagesize);
        NSLog(@" Converting ");
        [image drawInRect:CGRectMake(0,0,imagesize.width,imagesize.height)];
        newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();  

if not, can someone tell me how to distinguish between models.? Thanks

+5
source share
1 answer

You need to use UIGraphicsBeginImageContextWithOptionsinstead UIGraphicsBeginImageContextso that you can specify the scale factor of the image. This will use the scale factor of the device’s main screen:

UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);

, cellImage, cellImage :

UIGraphicsBeginImageContextWithOptions(imageSize, NO, cellImage.window.screen.scale);

:

UIGraphicsBeginImageContextWithOptions(imageSize, NO, 2);
+24

All Articles