# conveting colour image to blank n white

To convert color image in to black n white it first convert in to gray scale
by using formula

the formula that converts a color to gray shade is
R/G/B = (red * 0.30) + (green * 0.59) + (blue * 0.11)

and i write code in visual c++ 2008 express edition as

int grayval
for(int i=0;i<=bitmapsize;i++)
{
grayval=(pixel(i).red*0.30+pixel(i).green*0.59+pixel(i).blue*0.11);
}

now what is the next step to convert this gray image to black and white image
sir plz help me
i m very thankful to u
aansa

• use this bro

[code]
// i thought pixel. is struct-array
int grayval[bitmapsize+1];//i put +1 just to be sure you dont leak mem
for(int i=0;i<=bitmapsize;i++)
{
grayval[i]=(pixel[i].red*0.30+pixel[i].green*0.59+pixel[i].blue*0.11);
}

//if pixel. is a struct fuction, then
for(int i=0;i<=bitmapsize;i++)
{
grayval[i]=(pixel(i).red*0.30+pixel(i).green*0.59+pixel(i).blue*0.11);
}
[/code]
have fun bro
----------
gwbasic 10 CLS
qbasic A\$=INKEY\$
fortran printf("hello word");
labview |_|--->|_|-|-|_|----->o
c if(A=='q') {
cobol MOVE "hello world" TO A
c++ }
algol END
pascal .
• if you did get theimage with getimage()
read each pixel and use putpixel(x,y,color)
----------
gwbasic 10 CLS
qbasic A\$=INKEY\$
fortran printf("hello word");
labview |_|--->|_|-|-|_|----->o
c if(A=='q') {
cobol MOVE "hello world" TO A
c++ }
algol END
pascal .
• do you know how getimage() saves a pixel in memory? 3 bytes for 1pixel?
if so, delete each 3 bytes per pixel and write equal numbers of R G B for example: 0R,0G,0B is black, 255R,255G,255B is white, you want grey right, you have your formula greyval=.... get it and put it 3 times per pixel for each basic-color(r,g,b). or you can crash your OS
----------
gwbasic 10 CLS
qbasic A\$=INKEY\$
fortran printf("hello word");
labview |_|--->|_|-|-|_|----->o
c if(A=='q') {
cobol MOVE "hello world" TO A
c++ }
algol END
pascal .