views:

515

answers:

3

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?

A: 

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.

DHamrick
+3  A: 

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

[[view layer] setMagnificationFilter:kCAFilterNearest]
rpetrich
+2  A: 

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.

rekle