views:

176

answers:

3

I have a .PNG image with a transparent background and a drawing in it with a black color, how could I change the "black drawing color" in this image to any color i want programmatically; using rim 4.5 API ? THANKS IN ADVANCE ....

+1  A: 

You can parse the image RGBs searching for the black color and replace it with whatever color you desire.

Ali El-sayed Ali
Thanks Ali .... in next post you will find the implementation.
Ashraf Bashir
You are welcome, and nice implementation.
Ali El-sayed Ali
+1  A: 

I found the solution, here it is for those who are interested.

Bitmap colorImage(Bitmap image, int color) {
    int[] rgbData= new int[image.getWidth() * image.getHeight()];
    image.getARGB(rgbData, 
                  0, 
                  image.getWidth(), 
                  0, 
                  0, 
                  image.getWidth(), 
                  image.getHeight());
    for (int i = 0; i < rgbData.length; i++) {
        int alpha = 0xFF000000 & rgbData[i];
        if((rgbData[i] & 0x00FFFFFF) == 0x00000000)
            rgbData[i]= alpha | color;
    }
    image.setARGB(rgbData,
                  0, 
                  image.getWidth(),
                  0,
                  0,
                  image.getWidth(),
                  image.getHeight());
    return image;
}
Ashraf Bashir
Yes it will work, but it won't change any colours that are even slightly off-black, meaning any image which is aliased will end up looking rather ugly.
funkybro
A: 
Pavel Alexeev