We are conspiracy
Posts tagged programming
Creating one Pixel in a BMP in C
2754 jours
This thing is totally USELESS ! but i spend almost 3 day’s on it 
reading how BMP are made and to understand every parts of the BMP
header !
IF you’r looking good the pixel is there ====> above
I wanted something more easy than what i found on wikipedia for sample
in C so i wrote my own code … this is just useless and make only one red
pixel in a bmp file ( this will probably evolute to something better later )
but right now there is a pixel.
so this is the code
#include
int main(void){
FILE *f;
int filesize = 54 + 3*1*1;
unsigned char bmpfileheader[14] = {'B','M', 0,0,0,0, 0,0,0,0, 54,0,0,0};
unsigned char bmpinfoheader[40] = {40,0,0,0, 0,0,0,0, 0,0,0,0, 1,0, 24,0};
unsigned char bmpcontent[6] = {0,0,255};
unsigned char bmppad[3] = {0,0,0};
/* Construct header with filesize part */
bmpfileheader[ 2] = (unsigned char)(filesize );
bmpfileheader[ 3] = (unsigned char)(filesize>> 8);
bmpfileheader[ 4] = (unsigned char)(filesize>>16);
bmpfileheader[ 5] = (unsigned char)(filesize>>24);
/* Construct header with width and height part */
bmpinfoheader[ 4] = (unsigned char)( 1 );
bmpinfoheader[ 8] = (unsigned char)( 1 );
f = fopen("test.bmp","wb");
fwrite(bmpfileheader,1,14,f);
fwrite(bmpinfoheader,1,40,f);
fwrite(bmpcontent,3,6,f);
fclose(f);
return 1;
}
yes this code is totally not commented and will not be !
why ? because i’m actually lazy and if you want more some information on this … you can just contact me.
have a nice programming night.