Creating one Pixel in a BMP in C
This code was just a challenge, I wanted to create a simple image file with BMP headers. The following code simply generate pink pixel . There is actually a pixel on this post somewhere there —>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#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; } |
The code is pretty simple, however has not been commented, for more information have a look to the […]
Also tagged c, image, pixel, programming, red, useless