Advertisement
Guest User

Untitled

a guest
May 25th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.  
  7. char bitmap[1900];
  8.  
  9. // -- FILE HEADER -- //
  10.  
  11. // bitmap signature
  12. bitmap[0] = 0x42;
  13. bitmap[1] = 0x4d;
  14.  
  15. // file size
  16. bitmap[2] = 58; // 40 + 14 + 12
  17. bitmap[3] = 0;
  18. bitmap[4] = 0;
  19. bitmap[5] = 0;
  20. int i=0;
  21. // reserved field (in hex. 00 00 00 00)
  22. for(i = 6; i < 10; i++) bitmap[i] = 0;
  23.  
  24. // offset of pixel data inside the image
  25. for(i = 10; i < 14; i++) bitmap[i] = 0;
  26.  
  27. // -- BITMAP HEADER -- //
  28.  
  29. // header size
  30. bitmap[14] = 40;
  31. for(i = 15; i < 18; i++) bitmap[i] = 0;
  32.  
  33. // width of the image
  34. bitmap[18] = 4;
  35. for(i = 19; i < 22; i++) bitmap[i] = 0;
  36.  
  37. // height of the image
  38. bitmap[22] = 1;
  39. for(i = 23; i < 26; i++) bitmap[i] = 0;
  40.  
  41. // reserved field
  42. bitmap[26] = 1;
  43. bitmap[27] = 0;
  44.  
  45. // number of bits per pixel
  46. bitmap[28] = 24; // 3 byte
  47. bitmap[29] = 0;
  48.  
  49. // compression method (no compression here)
  50. for(i = 30; i < 34; i++) bitmap[i] = 0;
  51.  
  52. // size of pixel data
  53. bitmap[34] = 12; // 12 bits => 4 pixels
  54. bitmap[35] = 0;
  55. bitmap[36] = 0;
  56. bitmap[37] = 0;
  57.  
  58. // horizontal resolution of the image - pixels per meter (2835)
  59. bitmap[38] = 0;
  60. bitmap[39] = 0;
  61. bitmap[40] = 0b00110000;
  62. bitmap[41] = 0b10110001;
  63.  
  64. // vertical resolution of the image - pixels per meter (2835)
  65. bitmap[42] = 0;
  66. bitmap[43] = 0;
  67. bitmap[44] = 0b00110000;
  68. bitmap[45] = 0b10110001;
  69.  
  70. // color pallette information
  71. for(i = 46; i < 50; i++) bitmap[i] = 0;
  72.  
  73. // number of important colors
  74. for(i = 50; i < 54; i++) bitmap[i] = 0;
  75.  
  76. // -- PIXEL DATA -- //
  77. for(i = 54; i < 66; i++) bitmap[i] = 255;
  78.  
  79.  
  80. FILE *file;
  81. file = fopen("bitmap.bmp", "w+");
  82. for(i = 0; i < 66; i++)
  83. {
  84. fputc(bitmap[i], file);
  85. }
  86. fclose(file);
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement