为什么我的手机图像像素化?
我使用的是配备视网膜显示屏的 iPhone 4。
我有一个 60x60 png,它是从用作单元格 imageView 的 500x500 png 缩小而来的。
由于某种原因,图像看起来有点像素化和模糊,基本上不符合视网膜显示标准。
我做错了什么?
我正在使用 cell.imageView.image = [UIImage imageNamed:@"picture.png"];
I am using an iPhone 4 with retina display.
I have a 60x60 png that was downsized from a 500x500 png that I am using as the cell's imageView.
For some reason, the image looks a bit pixelated and blurry, basically not up to retina display standards.
What am I doing wrong?
I am using cell.imageView.image = [UIImage imageNamed:@"picture.png"];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 60x60 png 作为源。它可能会解决您的模糊问题,并且内存使用量也会更便宜。
我也经历过调整大小的图像变得模糊之类的情况。我可以想象这与图像在运行时缩小有关,尽管我不确定这一点。
另请记住,建议提供两个版本的图像文件:
一种用于正常分辨率(iPhone 3G、3GS ...):图片.png 适合您的情况:30x30px
一个用于视网膜显示屏 (iPhone 4):[电子邮件受保护] 适用于您的情况:60x60px。
Try using a a 60x60 png as a source. It will likely resolve your bluriness problems and will additionaly be cheaper on memory usage.
I have also experienced resized images to be blurry and the likes. I could imagine that this has something todo with the images being shrunken down at runtime, though I'm not sure about that.
Also remember that it's recommended to provide two versions of your imagefile:
One for normal resolutions (iPhone 3G, 3GS ...): picture.png for your case: 30x30px
One for the retina display (iPhone 4): [email protected] for your case: 60x60px.
由于文件名不遵循
[电子邮件受保护]< /code> 格式,iOS 无法识别它应该使用比例因子 2。有两种解决方案:
最好是提供两个版本图像:一个用于非视网膜显示器,其名称为
picture.png
,另一个是两倍大的用于视网膜显示器,其名称为[电子邮件受保护]
。您仍然可以使用[UIImage imageNamed:@"picture.png"];
,当设备具有视网膜显示屏并且有一个名为[电子邮件受保护]
它需要使用它。黑客解决方案(这将使您的图像在非视网膜设备上显示两倍大)是这样做的:
我建议采用
@2x
方式,这就是它应该完成的方式。Since the filename doesn't follow the
[email protected]
format, iOS doesn't recognize it should use a scale factor of 2. There are two solutions:The best is to provide two versions of the image: one for non-retina displays, which would be named
picture.png
and another one twice as big for retina displays, which would be named[email protected]
. You would still use[UIImage imageNamed:@"picture.png"];
, iOS automagically notices when the device has a retina display and there is a file called[email protected]
that it needs to use that instead.The hacky solution (which would make your image appear twice as big on non-retina devices) is to do this:
I recommend to go the
@2x
way, this is how it's supposed to be done.