Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Fill bitmap with colour

I'm working with Android and I really need a fast way to get a bitmap of a predetermined size to be filled with a predetermined colour.

The following code is not working for me however;

Bitmap input is a mutable bitmap

    int old = input.getPixel(0, 0);
    Canvas c = new Canvas(input);
    Rect rect = c.getClipBounds(); // The dimensions of the bitmap are returned
    c.drawARGB(a, r, g, b);
    int n = input.getPixel(0, 0);
    if(old==n)
        Log.e(TAG, "Values didn't change!");
    return input;

Rest assured, the 'old' value and the value of (a|r|g|b) are different but having 'drawn' the colour using a canvas with my mutable bitmap underneath, the bitmap retains it's old value.

I'd be happy with any method that takes a bitmap and a colour value and returns a bitmap filled with that colour.

like image 782
gav Avatar asked May 28 '09 21:05

gav


1 Answers

I didn't provide enough info!

My alpha value was out of range;

int a = 0xFF<<24

So when I called

c.drawARGB(a,r,g,b);

It failed quietly and didn't change the values.

like image 113
gav Avatar answered Sep 21 '22 17:09

gav