8

我在表格视图单元格中显示图像(图像名称保存在 plist 中)。在将其设置为单元格之前,我将图像大小调整为
imageSize = CGSizeMake(32, 32);

但是,在调整图像大小后,视网膜显示的质量也会下降。

在此处输入图像描述

我将两个图像都添加到项目中(即 1x 和@2x)。

这就是我将图像尺寸减小到 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;
}

非常感谢对此的任何指示。

谢谢

4

1 回答 1

19

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

于 2012-04-01T23:14:19.840 回答