views:

855

answers:

1

I want to draw a bitmap on a canvas with bigger size than it is. I can use canvas.drawBitmap(bitmap, null, destRect, null); but that gives a poor quality, as the result is pixelated, if the source image is sightly smaller than the destination rectangle.

How can i draw my bitmap using bilinear or bicubic resampling?

Any help would be appreciated, thanx.

+3  A: 

You need to set the FILTER_BITMAP_FLAG flag in your paint.

canvas.drawBitmap(bitmap, matrix, null); //ugly jaggies unless scale is 1:1, but fast

or

Paint paint = new Paint();
paint.setFilterBitmap();
canvas.drawBitmap(bitmap, matrix, paint); // pretty but slower (not too slow, usually)

The same applies to other (syntactic sugar) forms of the drawBitmap method.

There is no documentation anywhere for most of the Android drawing options and neither is there documentation for the underlying native Skia library that does the rendering. I'd be happier if there were. You can search the Skia source code on Google Code Search. Search for Skia and dig into the raw source; that's the only documentation.

Brian
Had to deal with this now, thanks for pointing out setFilterBitmap! Just to add a little more info from my findings, the interpolation for filter bitmap flag false is nearest neighbor and true is bilinear. Was hoping bicubic was available but doesn't look like it.
Dave