Click to See Complete Forum and Search --> : how bitmap data written into file


Rahul.Shendurnikar
March 17th, 2006, 01:43 AM
plz tell me , if we want to create .bmp file, after writtting all headers, how actual bit written in bitmap.
is that a row by row ie raster line, or any other type.

thanks in advance!!

golanshahar
March 17th, 2006, 02:09 AM
Look at this thread (http://www.codeguru.com/forum/showthread.php?t=346517&p=1180966) for sample.

Cheers

Rahul.Shendurnikar
March 17th, 2006, 05:18 AM
thanks for reply.
but my prblem is different .
in my project i get a pixel value in the form of RGB(colorreference), and i want to set that pixel value as a i/p of my bitmap data.
so i create a .bmp file firstly
then added a BITMAPFILESTRUCURE
then added a BITMAPINFOSTRUCTURE

and then i want to add actuall bitmap data.here i am giving my sample code.
FILE * fpTemp;
fp=fopen("C:\\Image.bmp","wb");


bheader.bfSize = sizeof( BITMAPFILEHEADER)+sizeof (BITMAPINFOHEADER)+(ImageWidth*ImageLength);
bheader.bfOffBits = 1078
bheader.bfReserved1 =0;
bheader.bfReserved2 = 0;
bheader.bfType =19778;
fwrite(&bheader,sizeof(struct tagBITMAPFILEHEADER),1,fp);

tagBITMAPINFOHEADER),1,fpTemp);

binfo.biWidth = (bottomright_x - topleft_x)+1;
binfo.biHeight =( - topleft_y + bottomright_y)+1;
binfo.biSize = 40;//sizeof(BITMAPINFOHEADER);
binfo.biSizeImage = 0;
binfo.biBitCount =8;
binfo.biClrImportant =0;
binfo.biClrUsed =0;//256;
binfo.biPlanes=1;
binfo.biCompression =0;//BI_RGB ;//
binfo.biXPelsPerMeter=0;
binfo.biYPelsPerMeter=0;
fwrite(&binfo,sizeof(struct tagBITMAPINFOHEADER),1,fp);

/ folowing code is an abstact of my codein which i get the value of //RED,GREEN,BLUE and this cntinues untill all pixel value get fetched.

rquad.rgbReserved = 0;
rquad.rgbRed = RED;
rquad.rgbGreen = GREEN;
rquad.rgbBlue = BLUE;
fwrite(&rquad,sizeof(RGBQUAD),1,fp);


fclose (fp);


==========
So plz tell me is it write or where is a problem in code.

golanshahar
March 17th, 2006, 05:42 AM
Fill a BYTE array in memory with the pixel data you are getting once you will have it full and you will have the width/height/bpp simply use the function I provided in the other post.

Cheers