UIImageView scaling/interpolation

左心房为你撑大大i 提交于 2019-12-18 14:59:12

问题


I have a small IPhone app that I am working on and I am displaying an image with a UIImageView. I am scaling it up using the Aspect Fit mode. I would like to have the image scale up with no interpolation/smoothing (I want it to look pixellated). Is there any way I can change this behavior?

A little more general question would be can I implement my own scaling algorithm, or are there other built in ones that I can select?


回答1:


You would need to set the magnificationFilter property on the view's layer to the nearest neighbour filter:

[[view layer] setMagnificationFilter:kCAFilterNearest]



回答2:


Make sure you include the line

#import  <QuartzCore/CALayer.h>

At the top of the file containing the call to setMagnificationFilter or it won't compile.




回答3:


Swift

imageView.layer.magnificationFilter = kCAFilterNearest
imageView.layer.shouldRasterize = true



回答4:


There are two ways you could do this. You can either implement a rescaling algrorithm without interpolation. If this is to much work you could rescale the image in another application like gimp or photoshop. This would work unless you needed to change the size dynamically in your application.



来源:https://stackoverflow.com/questions/1191868/uiimageview-scaling-interpolation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!