Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

iphone - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...