Home > Back-end >  Excuse me each me what's wrong with the BMP rotated 90 degrees? Rotation after documents show n
Excuse me each me what's wrong with the BMP rotated 90 degrees? Rotation after documents show n

Time:10-01

#include
#include
#include
The # pragma pack (1)
using namespace std;
Struct fileHEADER
{
WORD bfType;//the bitmap file type, must be "BM"
DWORD bfSize;//bitmap file size, in bytes
WORD bfReserved1;//bitmap file reserved words, must to 0
WORD bfReserved2;//bitmap file reserved words, must to 0
DWORD bfOffBits;//the bitmap data starting position to relative to the offset, said the bitmap file header in bytes
} FILEHEADER.
Struct tagHEADER {
DWORD biSize;//the structure of the number of bytes occupied
LONG biWidth;//the width of the bitmap, in pixels
LONG biHeight;//the height of the bitmap, in pixels
WORD biPlanes;//the target device plane countless, must be 1
WORD biBitCount;//number of bits required for each pixel, must be 1 (double color), 4 color (16), 8 (256) or one of the 24 (true color)
DWORD biCompression;//bitmap compression type, must be 0 (no compression), 1 (BI_RLE8 compression type) or 2 (BI_RLE4 compression type) is one of the
DWORD biSizeImage;//bitmap size, in bytes
LONG biXPelsPerMeter;//bitmap, horizontal resolution pixels per meter
LONG biYPelsPerMeter;//bitmap vertical resolution, pixels per meter
DWORD biClrUsed;//bitmap actual use of color in the color table number
DWORD biClrImportant;//in the process of the bitmap display important color number
} TAGHEADER;//this structure holds 40 bytes
Struct Colordata
{
BYTE blue, green, red;
};
Int main ()
{
Ifstream fin (" PKQ. BMP ", the ios: : | in ios: : binary);
if (! Fin)
Cout & lt; <"Fin error!" Fin. Read ((char *) & amp; FILEHEADER, sizeof (FILEHEADER));
Fin. Read ((char *) & amp; TAGHEADER, sizeof (TAGHEADER));
Int h=TAGHEADER biHeight, w=TAGHEADER. BiWidth;
int n;
N=(31) w * 24 +/8; N -=n % 4;
Int a=n - w * 3;
N=(31) * 24 h +/8; N -=n % 4;
Int b=n - h * 3;
Colordata * p=new Colordata (h * w),
for (int i=0; I & lt; h; + + I)
{
For (int j=0; J & lt; w; + + j)
Fin. Read ((char *) (p + I * w + j), sizeof (Colordata));
Fin. Seekg (a, the ios: : cur);
}
Fin. The close ();
TAGHEADER. BiHeight=w;
TAGHEADER. BiWidth=h;
FILEHEADER. BfSize=(h * 3 + b) * w + 54;
Cout & lt; Ofstream fout (" rotatepkq. BMP ", the ios: : out | ios: : binary);
if (! Fout)
Cout & lt; <"Fout error!" ;

Fout. Write ((char *) & amp; FILEHEADER, sizeof (FILEHEADER));
Fout. Write ((char *) & amp; TAGHEADER, sizeof (TAGHEADER));
For (int I=(w - 1); I & gt;=0; - I)
{

For (int j=0; J & lt; h; + + j)
Fout. Write ((char *) (p + I + j * w), sizeof (Colordata));
Fout. Seekp (b, the ios: : cur);
}
Fout. Close ();
The delete [] p;
return 0;
}
  • Related