Need a good quality bitmap rotation algorithm for Android

Posted by Lumis on Game Development See other posts from Game Development or by Lumis
Published on 2011-04-24T16:22:56Z Indexed on 2012/11/12 23:15 UTC
Read the original article Hit count: 241

Filed under:
|
|

I am creating a kaleidoscopic effect on an android tablet. I am using the code below to rotate a slice of an image, but as you can see in the image when rotating a bitmap 60 degrees it distorts it quite a lot (red rectangles) – it is smudging the image! I have set dither and anti-alias flags but it does not help much. I think it is just not a very sophisticated bitmap rotation algorithm.

canvas.save(); 
canvas.rotate(angle, screenW/2, screenH/2);
canvas.drawBitmap(picSlice, screenW/2, screenH/2, pOutput);
canvas.restore();

enter image description here

So I wonder if you can help me find a better way to rotate a bitmap. It does not have to be fast, because I intend to use a high quality rotation only when I want to save the screen to the SD card - I would redraw the screen in memory before saving.

Do you know any comprehensible or replicable algorithm for bitmap rotation that I could programme or use as a library? Or any other suggestion?

EDIT: The answers below made me think if Android OS had bilinear or bicubic interpolation option and after some search I found that it does have its own version of it called FilterBitmap. After applying it to my paint

pOutput.setFilterBitmap(true);

I get much better result

enter image description here

© Game Development or respective owner

Related posts about android

Related posts about rotation