المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Saving bitmap data [modified]



C++ Programming
12-15-2009, 01:30 PM
Hi

I am using following code to save 4 bit bitmap file.
.......
GetDIBits( dc, hBitmap, nStartScan, nNumScans, m_pVoid, lpBitmapInfo, wUsage);
.......

::ZeroMemory( &bFile, sizeof(bFile) );
memcpy( (void *)&bFile.bfType, "BM", 2 );
bFile.bfSize = GetDIBSize() + sizeof(bFile);
bFile.bfOffBits = sizeof(BITMAPINFOHEADER) + GetPaletteSize()*sizeof(RGBQUAD) + sizeof(BITMAPFILEHEADER);
file.Write(&bFile,sizeof(bFile));
file.Write(m_pVoid, GetDIBSize());
file.Close();

But the bitmap I got was shift. in following figure, each number was a pixel.

should be
---------
123456789
123456789
123456789
123456789
123456789

I got
---------
789123456
789123456
789123456
789123456
789123456

I know the problem was the starting of bitmap data which was saved to the Bitmap file.

I spent a lot of time on it. But I can not find the solution.

Please help.

modified on Monday, December 14, 2009 10:15 AM