Using Visual studio 2013(VC++) . Binary created (mfc SDI application) with x86 Configuration.
Application creates a BMP file from memory dc. (some 'fillrect' drawn)
Same application exec uted in Windows7 32 and 64 bit machines.
BMP file created in both machines are slightly different.
'Fillrect' drawn on 64 bit machine has 1 pixel more height.width same.
Mapping mode used is MM_ANISOTROPIC. (height is scaled)
Source
void CMFCApplication1View::OnDraw(CDC* pDC)
{
HDC hDc;
SIZE TempSize;
// We have create bmp file with 800 * 600 pixels
m_MemoryBmp.DeleteObject();
if (m_MemoryDC)
m_MemoryDC.DeleteDC();
if (!m_DummyWnd)
m_DummyWnd.Create(NULL, _T("DummyWindow"));
CClientDC WindowDC(&m_DummyWnd);
m_MemoryDC.CreateCompatibleDC(&WindowDC);
m_MemoryBmp.CreateCompatibleBitmap(&WindowDC, 800, 600);
m_MemoryDC.SelectObject(&m_MemoryBmp);
// set background color white
CRect rTotal(0, 0, 800, 600);
hDc = m_MemoryDC.GetSafeHdc();
int TempMapMode = GetMapMode(hDc);
COLORREF bkColor;
bkColor = RGB(255, 255, 255);
HBRUSH hBkgnd = NULL;
hBkgnd = CreateSolidBrush(bkColor);
SetBkColor(hDc, bkColor);
SetTextColor(hDc, RGB(0, 0, 0));
(HBRUSH)SelectObject(hDc, hBkgnd);
FillRect(hDc, &rTotal, hBkgnd);
// mapping mode set, height is scaled
CRect rLegend(632, 72, 792, 468);
GetWindowExtEx(hDc, &TempSize);
m_MemoryDC.SetMapMode(MM_ANISOTROPIC);
SetWindowExtEx(hDc, rLegend.Width(), 256, NULL);
SetViewportExtEx(hDc, rLegend.Width(), rLegend.Height(), NULL);
SetViewportOrgEx(hDc, rLegend.left, rLegend.top, NULL);
CRect rShape(0, 0, 53, 21);
// Draw shape
HBRUSH brShape = CreateSolidBrush(RGB(0, 255, 0));
SelectObject(hDc, brShape);
FillRect(hDc, &rShape, brShape); //green box
DeleteObject(brShape);
// Reset
SetWindowExtEx(hDc, TempSize.cx, TempSize.cy, NULL);
SetMapMode(hDc, TempMapMode);
// save bitmap
CImage TempImageObj;
WCHAR path[MAX_PATH];
TempImageObj.Attach((HBITMAP)m_MemoryBmp.Detach());
GetModuleFileName(NULL, path, MAX_PATH);
CString csPath(path);
int nIndex = csPath.ReverseFind(_T('\\'));
if (nIndex > 0) {
csPath = csPath.Left(nIndex);
csPath += _T("\\sample.bmp");
}
TempImageObj.Save(csPath);
// Release dc
::DeleteDC(hDc);
::DeleteObject(m_MemoryBmp.GetSafeHandle());
}
Following declared in .h file
CFrameWnd m_DummyWnd;
CBitmap m_MemoryBmp;
CDC m_MemoryDC;