Advertisement
Nicba1010

I am missing sth

Mar 16th, 2015
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. unsigned char* copyBMP(const char* filename, const char* hidden)
  2. {
  3.     string h = hidden;
  4.     ofstream geneModifier(hidden);
  5.     int i;
  6.     FILE* f = fopen(filename, "rb");
  7.     unsigned char info[54];
  8.     fread(info, sizeof(unsigned char), 54, f); // read the 54-byte header
  9.     for(i = 0; i < sizeof(info); i++)
  10.     {
  11.             geneModifier << info[i];
  12.     }
  13.     // extract image height and width from header
  14.     int width = *(int*)&info[18];
  15.     int height = *(int*)&info[22];
  16.  
  17.     int size = 3 * width * height;
  18.     unsigned char* data = new unsigned char[size]; // allocate 3 bytes per pixel
  19.     fread(data, sizeof(unsigned char), size, f); // read the rest of the data at once
  20.     fclose(f);
  21.     for(i = 0; i < size; i++)
  22.     {
  23.             geneModifier << data[i];
  24.     }
  25.     geneModifier.close();
  26.  
  27.     return data;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement