iphoneimageretina-displaypixelate

Loaded image in UIImage is pixelated on retina


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;

Solution

  • 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.