开发者

How to change the color of an image but can still recognize the object?

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).

What I want to do is just like this question: How would I tint an image programm开发者_如何学Goatically on iOS?

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


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);


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...)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜