1

When you put a UIImage into a UIImageView that is smaller than the view, and the content mode of the view is ScaleToFit, iOS enlarges the bitmap, as expected. What I have never expected is that it blurs the edges of the pixels it has scaled-up. I can see this might be a nice touch if you're looking at photographs, but in many other cases I want to see those nasty, hard, straight edges!

Does anyone know how you can configure a UIImage or UIImageView to enlarge with sharp pixel edges? That is: Let it look pixellated, not blurred.

Thanks!

Sujith Thankachan
  • 3,508
  • 2
  • 20
  • 25

1 Answers1

4

If you want to scale up any image in UIImageView with sharpen edge, use the following property of CALayer.

imageview.layer.magnificationFilter = kCAFilterNearest;

It seems that magnificationFilter affects an interpolation method of contents of UIView. I recommend you to read an explanation of the property in CALayer.h.

/* The filter types to use when rendering the `contents' property of
 * the layer. The minification filter is used when to reduce the size
 * of image data, the magnification filter to increase the size of
 * image data. Currently the allowed values are `nearest' and `linear'.
 * Both properties default to `linear'. */

@property(copy) NSString *minificationFilter, *magnificationFilter;

I hope that my answer is useful for you.

Kyokook Hwang
  • 2,682
  • 21
  • 36
  • That's great and achieves my purpose, but I want to ask, when I use `magnificationFilter = kCAFilterNearest`, are the big and sharp pixels magnified really the original pixels of the image, or just produced by some processing?Thank you! – Suge Nov 30 '14 at 01:22