Search code examples
iphoneiosuiimagescale

Scaling issue in saving UIImage as NSData


I would like to save some image as nsdata into a plist and retrieve it later. But I got a problem.

The problem is, if the UIImage with a scale of 2.0, when I load it again later with

[UIImage imageWithData:]

the image show 2x size

What I want is to like the behaviour of

[UIImage imageNamed:]

which will load according to the screen scale.

How can I do it?


Solution

  • I finally solve it by this code:

    UIImage *image = [UIImage imageWithData:imageData];
    if (isRetinaDisplay)  {
        image = [UIImage imageWithCGImage:[image CGImage] scale:2.0f orientation:UIImageOrientationUp];
    }