Draw bitmap as fast as possible with (whole number) scaling

I have a 640x480 RGB_565 format bitmap which I need to draw on a higher resolution display as fast as possible. It is not critical that the bitmap fills the entire screen so long as it fills most of it.

So, one idea I had was to draw a double sized bitmap 1280x960 so that each pixel in the original neatly maps to 4 pixels on screen. This, in theory, should be much faster than scaling to some awkward fraction. But I'm not sure exactly how to take advantage of this.

Would any of the possible canvas.drawBitmap functions notice the simple x2 calculation and do things faster? Should I perhaps make a double sized bitmap first and then draw the bigger bitmap without scaling? What would be the fastest way?

Answers


Mick, From what I understood - this is my answer to help you.

I have had a similar problem too. After reading some posts on Bitmap operations - I understood doing any pixel-by-pixel operations on a Bitmap is really slow on android.

For your problem, bitmap can be scaled using inbuilt functions (which generally work faster than pixel by pixel operations). This is the way to use the inbuilt functions :

bitmapProcessed = Bitmap.createScaledBitmap(originalBitmap, NewWidth, NewHeight, true);

In your case,

NewWidth  = 2 * originalBitmap.getWidth();
NewHeight = 2 * originalBitmap.getHeight();

The image that results from this, is generally not very good. If you want to make it more clear, to match the higher resolution display - I would suggest doing a bicubic interpolation.

I hope this helps.


Need Your Help

Modify Windows Command Prompt History from a Program?

windows console cmd

Is there an API to add to the a windows command prompt history? I writing a console program and it would be handy to pop some commands into the history buffer under certain (limited) conditions.

Array with loops Java

java arrays loops

I want to print put the elements in an array that only occur twice. So if, for example, number 2 occurs 3 or 4 times, it should not be printed. The code I've written so far is below.