What does the filter parameter to createScaledBitmap do? What does the filter parameter to createScaledBitmap do? android android

What does the filter parameter to createScaledBitmap do?


To expand on Karan's answer: As a general rule you won't see any difference if you're scaling your image down, but you will if you're scaling it up.

Passing filter = false will result in a blocky, pixellated image.

Passing filter = true will give you smoother edges.

However, as EIYeante pointed out in the comments, you might still see a difference. This is their example image.


A quick dig through the SKIA source-code indicates that (at least by default) the FILTER flag causes it to do a straightforward bilinear interpolation. Check Wikipedia or your favorite graphics reference to see what the expected consequences are. Traditionally, you want to do bilinear or bicubic interpolation when upsizing images, and area averaging when downsizing images. I get the impression (though I'm glad to be corrected) that Android/Skia does simple subsampling when downsizing without filtering, so you are likely to get better results from filtering even when downsizing. (There's an alternate method for getting high quality downsizing with interpolation, involving doing a series of 50% scale reductions. See http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html for details.)


Filter will set the FILTER_BITMAP_FLAG for painting which affects the sampling of bitmaps when they are transformed based on the value that you provide.