Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- char bitmap[1900];
- // -- FILE HEADER -- //
- // bitmap signature
- bitmap[0] = 0x42;
- bitmap[1] = 0x4d;
- // file size
- bitmap[2] = 58; // 40 + 14 + 12
- bitmap[3] = 0;
- bitmap[4] = 0;
- bitmap[5] = 0;
- int i=0;
- // reserved field (in hex. 00 00 00 00)
- for(i = 6; i < 10; i++) bitmap[i] = 0;
- // offset of pixel data inside the image
- for(i = 10; i < 14; i++) bitmap[i] = 0;
- // -- BITMAP HEADER -- //
- // header size
- bitmap[14] = 40;
- for(i = 15; i < 18; i++) bitmap[i] = 0;
- // width of the image
- bitmap[18] = 4;
- for(i = 19; i < 22; i++) bitmap[i] = 0;
- // height of the image
- bitmap[22] = 1;
- for(i = 23; i < 26; i++) bitmap[i] = 0;
- // reserved field
- bitmap[26] = 1;
- bitmap[27] = 0;
- // number of bits per pixel
- bitmap[28] = 24; // 3 byte
- bitmap[29] = 0;
- // compression method (no compression here)
- for(i = 30; i < 34; i++) bitmap[i] = 0;
- // size of pixel data
- bitmap[34] = 12; // 12 bits => 4 pixels
- bitmap[35] = 0;
- bitmap[36] = 0;
- bitmap[37] = 0;
- // horizontal resolution of the image - pixels per meter (2835)
- bitmap[38] = 0;
- bitmap[39] = 0;
- bitmap[40] = 0b00110000;
- bitmap[41] = 0b10110001;
- // vertical resolution of the image - pixels per meter (2835)
- bitmap[42] = 0;
- bitmap[43] = 0;
- bitmap[44] = 0b00110000;
- bitmap[45] = 0b10110001;
- // color pallette information
- for(i = 46; i < 50; i++) bitmap[i] = 0;
- // number of important colors
- for(i = 50; i < 54; i++) bitmap[i] = 0;
- // -- PIXEL DATA -- //
- for(i = 54; i < 66; i++) bitmap[i] = 255;
- FILE *file;
- file = fopen("bitmap.bmp", "w+");
- for(i = 0; i < 66; i++)
- {
- fputc(bitmap[i], file);
- }
- fclose(file);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement