Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- struct palette
- {
- unsigned char rgbBlue;
- unsigned char rgbGreen;
- unsigned char rgbRed;
- unsigned char rgbReserved;
- };
- void main()
- {
- int i,j;
- unsigned short int bfType;
- int bfSize;
- unsigned short int bfReserved1;
- unsigned short int bfReserved2;
- int bfOffBits;
- int biSize;
- int biWidth;
- int biHeight;
- unsigned short int biPlanes;
- unsigned short int biBitCount;
- int biCompression;
- int biSizeImage;
- int biXPelsPerMeter;
- int biYPelsPerMeter;
- int biClrUsed;
- int biClrImportant;
- struct palette pal[256];
- unsigned char ** immagine;
- FILE *fp,*fpout;
- fp = fopen ("gate.bmp","rb");
- fpout=fopen("immagine.bmp","wb");
- fread (&bfType, sizeof(unsigned short int),1,fp);
- fread (&bfSize, sizeof(int),1,fp);
- fread (&bfReserved1, sizeof(unsigned short int),1,fp);
- fread (&bfReserved2, sizeof(unsigned short int),1,fp);
- fread (&bfOffBits, sizeof(int),1,fp);
- fread (&biSize, sizeof(int),1,fp);
- fread (&biWidth, sizeof(int),1,fp);
- fread (&biHeight, sizeof(int),1,fp);
- fread (&biPlanes, sizeof(unsigned short int),1,fp);
- fread (&biBitCount, sizeof(unsigned short int),1,fp);
- fread (&biCompression, sizeof(int),1,fp);
- fread (&biSizeImage, sizeof(int),1,fp);
- fread (&biXPelsPerMeter, sizeof(int),1,fp);
- fread (&biYPelsPerMeter, sizeof(int),1,fp);
- fread (&biClrUsed, sizeof(int),1,fp);
- fread (&biClrImportant, sizeof(int),1,fp);
- fread (pal, sizeof(pal), 1 ,fp);
- biWidth=(int)64;
- biHeight=(int)64;
- immagine = new unsigned char*[biHeight];
- for (i=0; i < biHeight; i++)
- immagine[i]= new unsigned char[biWidth];
- //SCRITTURA HEADER BMP
- fwrite (&bfType, sizeof(unsigned short int),1,fpout);
- fwrite (&bfSize, sizeof(int),1,fpout);
- fwrite (&bfReserved1, sizeof(unsigned short int),1,fpout);
- fwrite (&bfReserved2, sizeof(unsigned short int),1,fpout);
- fwrite (&bfOffBits, sizeof(int),1,fpout);
- fwrite (&biSize, sizeof(int),1,fpout);
- fwrite (&biWidth, sizeof(int),1,fpout);
- fwrite (&biHeight, sizeof(int),1,fpout);
- fwrite (&biPlanes, sizeof(unsigned short int),1,fpout);
- fwrite (&biBitCount, sizeof(unsigned short int),1,fpout);
- fwrite (&biCompression, sizeof(int),1,fpout);
- fwrite (&biSizeImage, sizeof(int),1,fpout);
- fwrite (&biXPelsPerMeter, sizeof(int),1,fpout);
- fwrite (&biYPelsPerMeter, sizeof(int),1,fpout);
- fwrite (&biClrUsed, sizeof(int),1,fpout);
- fwrite (&biClrImportant, sizeof(int),1,fpout);
- //fwrite (pal, sizeof(pal), 1 ,fpout);
- for (i=0 ; i < biHeight ; i++)
- {
- for(j=0; j<biWidth; j++)
- {
- if((i+j)%2==0) immagine[i][j]=255;
- else immagine[i][j]=0;
- }
- };
- for (i=0 ; i < biHeight ; i++)
- {
- for(j=0; j<biWidth; j++)
- {
- fwrite(&immagine[i][j], sizeof(unsigned char),1,fpout);
- };
- };
- fclose(fp);
- fclose(fpout);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement