Home > Back-end >  BMP bitmap storage problem
BMP bitmap storage problem

Time:09-26

Screenshots to write data

I have written in c + + stand out figure size of 1 * 1 pixel display normal 24 true-color output

But I use a hexadecimal view file data right

Should be after 54 byte + 4 bytes of data (3 bytes color and 1 byte alignment)

Hexadecimal view there are 7 bytes???

Sometimes is right 4 bytes



CodePudding user response:

Capture the image of key code

 


//interception picture
Bool pixelex: : captrue (long long x, long y, long w, h, char * filepath)
{
//path processing
//setpath (filepath);
Filepath="c:/123. TXT".
Long pixelLength;
Byte * pixelDate=NULL;
The FILE * wfile=NULL;
//open the file
Wfile=fopen (filepath, "wb");
Fwrite (head, 54, 1, wfile);
//change the grab. BMP height and width of the header file
Fseek (wfile, 0 x0012, SEEK_SET);
Fwrite (& amp; W, sizeof (w), 1, wfile);
Fwrite (& amp; H, sizeof (h), 1, wfile);
//allocate memory for pixel
PixelLength=w * 3;
If (pixelLength % 4!=0)
{
4 - pixelLength pixelLength +=% 4;
}
PixelLength *=h;
PixelDate=(byte *) malloc (pixelLength);
If (pixelDate==0)
{
AfxMessageBox (L "memory allocation failure");
}

If (ishaverc)
{
GlReadPixels (x, y, w, h, GL_BGR_EXT, GL_UNSIGNED_BYTE, pixelDate);
glFlush();
//AfxMessageBox (L "has");
} the else
{
Bool ok=apihook: : getdx () - & gt; Readpix (x, y, w, h, pixelDate);
if(! Ok)
{
The fclose (wfile);
Free (pixelDate);
return false;
}
//AfxMessageBox (L "no");
}


Cstrings o;
O.F ormat (L "% d", pixelLength);
AfxMessageBox (o);
There is nothing wrong with//output has been here 4

Fseek (wfile, 0, SEEK_END);
Fwrite (pixelDate pixelLength, 1, wfile);
The fclose (wfile);
Free (pixelDate);
return true;
}







CodePudding user response:

Key point is not BMP should be 4 byte aligned but 7 bytes. It is normal yellow,,,,,,,,
  • Related