Question

I am displaying an image in tableview cell (Image name saved in a plist). Before setting it to the cell, I am resizing the image to
imageSize = CGSizeMake(32, 32);

But, after resizing the image, quality is also getting degraded in retina display.

enter image description here

I have both the images added to the project (i.e. 1x and @2x).

This is how I am reducing the image size to 32x32.

+ (UIImage *)scale:(UIImage *)image toSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}

Any pointers on this is very much appreciated.

Thanks

Was it helpful?

Solution

try this : instead of UIGraphicsBeginImageContext(size);use UIGraphicsBeginImageContextWithOptions(size,NO,0.0);

from what i understand what you're doing there is resizing the image to 32x32 (in points) no matter what the resolution. the UIGraphicsBeginImageContextWithOptions scales the image to the scale of the device's screen..so you have the image resized to 32x32 points but the resolution is kept for retina display

(note that this is what i understood from apple's uikit reference..it may not be so..but it should) read here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top