views:

51

answers:

2

The title maybe a little vague, let me give you an example: if we change a colorful image into black and white, we still can recognize the objects in it. My question is, can I change the color to RED or GREEN or other color rather than black and white in programs(I prefer Java).

[Update] : what I want to do is just like this question:

http://stackoverflow.com/questions/1117211/how-would-i-tint-an-image-programatically-on-the-iphone

However, I want to do this on Android instead of iphone ....

A: 

Yes when converting to grayscale (this is what it is, 256 shades of gray, not black and white) you are somehow (depending on algorithm) mapping the intensity of the original colors into a value n in the 0-255 range and then setting all pixels to be (n,n,n) which will give you a shade of gray, 0 being black and 255 being white. Now if you use (n, 0, 0) instead, you'll get an image with varying intensity of red.

(as I write this I'm getting more and more doubtful that I understood your question correctly...)

MK
Thanks for your answer! I updated the question, check it again.
wong2
+1  A: 

Do something like this

Bitmap sourceBitmap = BitmapFactory... 

float[] colorTransform = .. // read ColorMatrix docs to understand the transform
ColorMatrix colorMatrix = new ColorMatrix();

ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
Paint paint = new Paint();
paint.setColorFilter(colorFilter);         

Bitmap resultBitmap = Bitmap.createBitmap(
     sourceBitmap.getWidth(), 
     sourceBitmap.getHeight(),
     Bitmap.Config.RGB_565);

 Canvas canvas = new Canvas(resultBitmap);
 canvas.drawBitmap(sourceBitmap, 0, 0, paint);

int pixelColor=resultBitmap.getPixel(123,321);
Peter Knego
thanks. Color filter is the right thing to turn to.
wong2