Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImageView scaling/interpolation

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?

like image 323
Dolphin Avatar asked Jul 28 '09 03:07

Dolphin


People also ask

Do Iphones use interpolation?

By default, we get image interpolation, which is where iOS blends the pixels so smoothly you might not even realize they have been stretched at all.

How do I change the UIImage size in Swift?

Show activity on this post. extension UIImage { func imageResize (sizeChange:CGSize)-> UIImage{ let hasAlpha = true let scale: CGFloat = 0.0 // Use scale factor of main screen UIGraphicsBeginImageContextWithOptions(sizeChange, ! hasAlpha, scale) self. draw(in: CGRect(origin: CGPoint.


1 Answers

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

[[view layer] setMagnificationFilter:kCAFilterNearest]
like image 60
rpetrich Avatar answered Oct 21 '22 13:10

rpetrich