Advertisement
4da

BMP read

4da
Oct 16th, 2011
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. //считывание в main
  2.     FILE * source = fopen(sourcefn, "rb");
  3.     BMP ImageIn;
  4.     ImageIn.ReadFromFile( sourcefn );
  5.  
  6.  
  7.     int width = ImageIn.TellWidth();
  8.     int height =  ImageIn.TellHeight();
  9.     cout<<"readRGBA"<<endl;
  10.     char * buffer = new char[width*height*BYTES];
  11.  
  12.     for(int j = 0; j<height; j++)
  13.     {
  14.         for(int i = 0; i<width; i++)
  15.         {
  16.             RGBApixel pix =  ImageIn.GetPixel(i,j);
  17.             buffer[BYTES*(j*width+i) + 0] = pix.Blue;
  18.             buffer[BYTES*(j*width+i) + 1] = pix.Green;
  19.             buffer[BYTES*(j*width+i) + 2] = pix.Red;
  20.             buffer[BYTES*(j*width+i) + 3] = 127;
  21.         }
  22.     }
  23.  
  24. //запись в rekurswrite
  25.  
  26.         BMP ImageOut;
  27.         ImageOut.SetSize( 1024, 1024 );
  28.         ImageOut.SetBitDepth( 32 );
  29.         for(int j = 0; j<SCBLOCK_H; j++)
  30.             for(int i = 0; i< SCBLOCK_W; i++)
  31.             {
  32.                 RGBApixel pix;
  33.                 pix.Red = subimage[BYTES*j*SCBLOCK_W+i + 0];
  34.                 pix.Green = subimage[BYTES*j*SCBLOCK_W+i + 1];
  35.                 pix.Blue = subimage[BYTES*j*SCBLOCK_W+i + 2];
  36.                 pix.Alpha = 0;
  37.                 ImageOut.SetPixel( i, j, pix);
  38.             }
  39.         string title = source+string(".bmp");
  40.         const char * name =   title.c_str();
  41.         ImageOut.WriteToFile(name);
  42.  
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement