1

I parsed the data from a web which also contains jpg image. The problem is that the image looks blurry/pixelated on retina display. Any solution for this? Thanks.

NSData *data = [NSData dataWithContentsOfURL:linkUrl];
            UIImage *img = [[UIImage alloc] initWithData:data];   

          //  detailViewController.faces.contentScaleFactor=[UIScreen mainScreen].scale;//Attampt to solve the problem

            detailViewController.faces.image=img;
Benjamen
  • 609
  • 1
  • 5
  • 13

1 Answers1

4

After initializing your image with the data, create a new one from it with the correct scale like this:

img = [UIImage imageWithCGImage:img.CGImage scale:[UIScreen mainScreen].scale orientation:img.imageOrientation];

...but note that the image will now appear half the size on retina displays unless you scale it up, for example by stretching it in an image view.

jhabbott
  • 18,461
  • 9
  • 58
  • 95
  • it says use of undeclared identifier "image". I replaced it with "img" but the images are still pixelated. Thanks. – Benjamen Jul 06 '12 at 18:30
  • With this code it is also blurry. Without it it is just pixelated. Thank you though. – Benjamen Jul 06 '12 at 18:36
  • 1
    Yes, the reason is because the image you are loading is too small in pixels, and so your image view is scaling it up (to fill the frame of your image view). You need to load a bigger image, and set the scale like in my example so that it doesn't get shrunk down on retina displays. For example if your image view `frame` is `{{10, 10}, {100, 100}}` then you need to load a 200x200 image for retina displays and 100x100 for standard displays (and set the scale correctly, like above). – jhabbott Jul 06 '12 at 20:10
  • I don't have a chance to load a bigger image. I just wanted to show it the way it is on the web. I accept your answer though. – Benjamen Jul 06 '12 at 20:39