Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIGraphicsGetImageFromCurrentImageContext retina resolutions?

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

The above statement i am sure will make appropriate sizes in both retina resolution devices and standard ones..that is a frame of 107 x 70 pixels on standard and 214 x 140 on retina.

What i want to know is if the below UIGraphicsGetImageFromCurrentImageContext does the same too.. image will 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 anyone tell me how to differentiate between models.? Thanks

like image 738
Shubhank Avatar asked Feb 14 '12 09:02

Shubhank


1 Answers

You need to use UIGraphicsBeginImageContextWithOptions instead of UIGraphicsBeginImageContext, so 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);

This will use the scale factor of the screen containing cellImage, if cellImage is on a screen:

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

This will hardcode the scale factor:

UIGraphicsBeginImageContextWithOptions(imageSize, NO, 2);
like image 171
rob mayoff Avatar answered Oct 30 '22 04:10

rob mayoff