UIViewContentModeScaleAspectFit iPhone SDK给出的图像质量较差 [英] UIViewContentModeScaleAspectFit iphone sdk gives poor quality image

查看:51
本文介绍了UIViewContentModeScaleAspectFit iPhone SDK给出的图像质量较差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望是一个快速的人?我正在创建自定义uitableviewcell并添加了imageview. 我有一些尺寸约为200x200的PNG图片.我想创建一个缩略图放入表格视图中,但是当我调整图像大小时,会导致图像质量较差.

Hopefully a quick one? I am creating a custom uitableviewcell and have added an imageview. I have some PNG images which are around 200x200 in size. I want to create a thumbnail to put in the tableview, but when I resize the image, it results in a poor quality image.

我使用UIViewContentModeScaleAspectFit将其尺寸调整为50x50帧.

I use UIViewContentModeScaleAspectFit to resize it to a 50x50 frame.

在将每个图像放到表格单元格之前,我应该对每个图像调用更好的绘制调整大小吗?每个表中将有大约20-40张图像,所以我不想让设备工作过度!

Should I be calling a better draw resize on each image before I Put it to the table cell? There will be around 20-40 images in each table, so I don't want to over work the device!!

感谢您的帮助.

推荐答案

使用CoreGraphics自己重新缩放图像将使您对质量有更多的控制权,但是最好的选择是首先为表格适当地调整图像大小- -软件要做的工作更少,可以完全控制图像的外观.

Rescaling the images yourself with CoreGraphics will give you more control over the quality, but your best bet is to size the images appropriately for your table in the first place -- less work the software has to do and complete control over the image's appearance.

如果您仍然想在Quartz中调整它们的大小,可以采用以下一种方法:

If you still want to resize them in Quartz, here's one way you might go about it:

UIImage* originalThumbnail = [UIImage imageWithContentsOfFile:<PATH_TO_IMAGE>];

CGSize originalSize = [originalThumbnail size];
CGSize cropSize = { 50, 50 };

CGRect cropRect = CGRectMake(abs(cropSize.width - originalSize.width)/2.0, abs(cropSize.height - originalSize.height)/2.0, cropSize.width, cropSize.height);

CGImageRef imageRef = CGImageCreateWithImageInRect([originalThumbnail CGImage], cropRect);

// here's your cropped UIImage
UIImage* croppedThumbnail = [UIImage imageWithCGImage:imageRef];  
CGImageRelease(imageRef);

如果可能的话,您只想执行一次,即,并非每次构造UITableViewCell时都要做.

You'd want to do this once if possible, i.e. not every time you construct your UITableViewCell.

这篇关于UIViewContentModeScaleAspectFit iPhone SDK给出的图像质量较差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆