user225626
user225626

Reputation: 1099

Turning a color bmp to grayscale:

I've seen this code on the web:

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

Canvas c = new Canvas(grayscaleBitmap); 
Paint p = new Paint(); 
ColorMatrix cm = new ColorMatrix(); 

cm.setSaturation(0); 
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(cm); 
p.setColorFilter(filter);  
c.drawBitmap(bmp, 0, 0, p); 

My questions are: 1. Is 'bmp' supposed to be the color bitmap I want to affect? 2. How do I get the 0-255 value of the grayscale?

Thanks.

Upvotes: 1

Views: 1249

Answers (1)

Michael Todd
Michael Todd

Reputation: 17081

  1. That depends on how bmp is defined (but it looks like that is a correct assumption)
  2. gray = (0.299*r + 0.587*g + 0.114*b); (from here)

Upvotes: 2

Related Questions