I'd like to display a color image in black and white only ? What should I adjust ?
Thanks a lot
Printable View
I'd like to display a color image in black and white only ? What should I adjust ?
Thanks a lot
Here is a link to convert a color bitmap into monochrome.
http://support.microsoft.com/default.aspx/kb/77282
When you say black and white, do you mean monochrome (literally only black pixel or white pixel) or do you mean greyscale (like a black and white photo)?
If the former, see _Superman_'s link. If the latter, you'll have to go through each pixel and apply a formula to the red, green, and blue components, to convert to greyscale equivalent. The mathematical formula is:
grey=0.2125*red+0.7154*green+0.0721*blue;
To do this to an image, use something like this in a loop:
Code:unsigned cr,rd,gn,bl,av;
for(;;) //do whatever to loop through your image here
{
cr=GetPixel(hdc,x,y);
rd=GetRValue(cr);
gn=GetGValue(cr);
bl=GetBValue(cr);
av=(rd*2125+gn*7154+bl*721)/10000;
SetPixel(hdc,x,y,RGB(av,av,av));
}