'Draw a scaled Bitmap to the Canvas?

The following code defines my Bitmap:

Resources res = context.getResources();

mBackground = BitmapFactory.decodeResource(res, R.drawable.background);

// scale bitmap
int h = 800; // height in pixels
int w = 480; // width in pixels
// Make sure w and h are in the correct order
Bitmap scaled = Bitmap.createScaledBitmap(mBackground, w, h, true);

... And the following code is used to execute/draw it (the unscaled Bitmap):

canvas.drawBitmap(mBackground, 0, 0, null);

My question is, how might I set it to draw the scaled Bitmap returned in the form of Bitmap scaled, and not the original?



Solution 1:[1]

To draw the scaled bitmap you want save your scaled bitmap in a field somewhere (here called mScaled) and call:

canvas.drawBitmap(mScaled, 0, 0, null);

in your draw method (or wherever you call it right now).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hata