szubert

Lab 5 a&ds

May 20th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <iostream>
  4. #include <string.h>
  5.  
  6. #define FILE_IN "i23.bmp"
  7. #define FILE_OUT "i23_enc.bmp"
  8.  
  9. using namespace std;
  10.  
  11. int main() {
  12.     int i;
  13.     char header[54], headerNew[54];
  14.     char R0, G0, B0, R, G, B;
  15.     int size; //correspond to number of pixels of image
  16.     FILE *fin;
  17.     FILE *fout;
  18.  
  19.     fin = fopen(FILE_IN, "rb");
  20.     fout = fopen(FILE_OUT, "wb");
  21.  
  22.     if (fin == NULL) {
  23.         printf("Cannot open file.\n");
  24.         exit(1);
  25.     }
  26.  
  27.     fread(header, sizeof(char), 54, fin);
  28.  
  29.     fseek(fout, 0, SEEK_SET);
  30.  
  31.     for (i = 0; i < 54; i++) {
  32.         fputc(header[i], fout);
  33.     }
  34.  
  35.     fread(headerNew, sizeof(char), 54, fout);
  36.  
  37.     int width = *(int*)&header[18];
  38.     int height = *(int*)&header[22];
  39.  
  40.     int width1 = *(int*)&headerNew[18];
  41.     int height2 = *(int*)&headerNew[22];
  42.  
  43.     cout <<width1 << "  " << height2 << endl;
  44.  
  45.     fclose(fin);
  46.     fclose(fout);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment