简体   繁体   English

Pixelart使用UIImageView变得模糊

[英]Pixelart gets fuzzy using UIImageView

I have an 16 * 16 pixel art image which i want to use in my iOS app. 我有一个16 * 16像素的艺术图像,我想在我的iOS应用程序中使用。
but when i select the image at my UIImageView the picture gets really blurry. 但是当我在UIImageView上选择图像时,图像变得非常模糊。

I think it has something to do with the way the image gets filtered, but i couldn't find any filtering options. 我认为这与图像被过滤的方式有关,但我找不到任何过滤选项。 I already tried changing a lot of options, but just can't get it to work 我已经尝试过改变很多选项,但却无法让它发挥作用

How do i fix this? 我该如何解决?

( i am using iOS 7, Xcode 5.1.1, OS X 10.9 Mavericks and a iPhone 4S (i don't think this info is needed, but just in case)) (我使用的是iOS 7,Xcode 5.1.1,OS X 10.9 Mavericks和iPhone 4S(我认为不需要这些信息,但以防万一))

EDIT: 编辑:

Here's an image: http://i.stack.imgur.com/d3Yms.png 这是一张图片: http//i.stack.imgur.com/d3Yms.png

As you can see, the image on the right in photoshop looks great, but the image on the left in Xcode looks fuzzy 正如您所看到的,Photoshop中右侧的图像看起来很棒,但Xcode左侧的图像看起来很模糊

The problem is that scaling procedure interpolates pixels position and size while scaling it. 问题是缩放过程在缩放时插入像素位置和大小。 If you want to use sharp pixelart-images you must prepare all resources and never rely on scaling by setting 如果你想使用锐利的pixelart图像,你必须准备所有资源,而不是依靠设置缩放

_imageView.contentMode = UIVIewContentModeCenter;

OR set scaling filters to value kCAFilterNearest 或者将缩放过滤器设置为值kCAFilterNearest

[_imageView.layer setMagnificationFilter:kCAFilterNearest];
[_imageView.layer setMinificationFilter:kCAFilterNearest];

if you like the second way, i'd recommend to set all ImageView frames with EVEN (2,4,6,8 etc) sizes and origins to avoid pixel misalign 如果您喜欢第二种方式,我建议设置所有具有偶数(2,4,6,8等)尺寸和原点的ImageView帧以避免像素错位

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM