Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Change the Color of bitmap and retaining shades in bitmap?

I am working in a android project where in i have to change the color of the wall. For e.x if I take a picture of the wall having corners and select some color say blue. The color of the wall should change in such a way that the wall looks as if it is painted with that color. I mean to say that the shades at the corners of the wall should be retained after changing the color. Wall should not look like painted like flat rectangle.

Please let me know the way to do it.

Thanks in advance. Regards

like image 770
Kantesh Avatar asked Sep 26 '12 12:09

Kantesh


People also ask

How do I change the bitmap color in Android?

BitmapDrawable BD = (BitmapDrawable) I. getDrawable(); bitmap = BD. getBitmap(); Then when ever user clicks the button we set the second bitmap variable with the first variable and change the color of the ImageView like this: O = Bitmap.

What is a color bitmap?

A bitmap is an array of bits that specifies the color of each pixel in a rectangular array of pixels. The number of bits devoted to an individual pixel determines the number of colors that can be assigned to that pixel.


2 Answers

Try the bellow link

How to change Bitmap image color in android?

Or

http://www.codeproject.com/Articles/17162/Fast-Color-Depth-Change-for-Bitmaps

OR

how to change the color of certain pixels in bitmap android

This may help You.

like image 76
bashu Avatar answered Sep 29 '22 07:09

bashu


Here is something I did for getting it done:

public static Bitmap changeImageColor(Bitmap srcBmp, int dstColor) {

    int width = srcBmp.getWidth();
    int height = srcBmp.getHeight();

    float srcHSV[] = new float[3];
    float dstHSV[] = new float[3];

    Bitmap dstBitmap = Bitmap.createBitmap(width, height, Config.RGB_565);

    for (int row = 0; row < height; row++) {
        for (int col = 0; col < width; col++) {
            Color.colorToHSV(srcBmp.getPixel(col, row), srcHSV);
            Color.colorToHSV(dstColor, dstHSV);

            // If it area to be painted set only value of original image
            dstHSV[2] = srcHSV[2];  // value

            dstBitmap.setPixel(col, row, Color.HSVToColor(dstHSV));
        }
    }

    return dstBitmap;
}
like image 30
Kantesh Avatar answered Sep 29 '22 07:09

Kantesh