-
June 30th, 2010, 11:51 AM
#1
Scaling issue when replaying metafile
I am trying to replay a metafile that has been saved on the disk. It works except for one thing. I cannot figure out how to get a proper scaling. If I don't do anything, when drawing the bitmap on the screen from the metafile, it appears much, much bigger than it should. Well, given that the window size is 100*100, it never exceeds that on the screen, but it means only a small part of a much bigger bitmap is visible.
Here is a code sample that reproduces the problem.
Code:
void CreateMetafile()
{
CString strFileName = "c:\\test\\test.emf";
CMetaFileDC memDC;
CRect rect (0, 0, 100, 100);
memDC.CreateEnhanced(&memDC, strFileName, rect, "just a test");
CBrush m_brush(RGB(255,255,255));
CPen m_pen(PS_SOLID, 1, COLORREF(RGB(0, 255, 0)));
memDC.SelectObject(&m_brush);
memDC.SelectObject(&m_pen);
memDC.SetBkMode(TRANSPARENT);
memDC.Rectangle(0,0,rect.Width(),rect.Height());
memDC.MoveTo(0, 0);
memDC.LineTo(100, 100);
HENHMETAFILE hmf = memDC.CloseEnhanced();
DeleteEnhMetaFile(hmf);
}
void ReplayMetafile()
{
CWnd wnd;
CRect rect (100, 100, 200, 200);
wnd.CreateEx(NULL, NULL, NULL,WS_POPUP | WS_CHILD | WS_CLIPSIBLINGS, rect, NULL, NULL, NULL);
hmf = GetEnhMetaFile(strFileName);
CRect rectWnd = rect;
CPoint ptToolTipLeft = rectWnd.TopLeft();
SetWindowPos(wnd.m_hWnd, HWND_TOPMOST,ptToolTipLeft.x+1, ptToolTipLeft.y+1, rectWnd.Width(), rectWnd.Height(),SWP_SHOWWINDOW|SWP_NOOWNERZORDER|SWP_NOACTIVATE);
CClientDC paintdc(&wnd);
int ratio = 1;
paintdc.SetMapMode(MM_ANISOTROPIC);
paintdc.SetWindowExt(100*ratio, 100*ratio);
paintdc.SetViewportExt(100, 100);
CRect rect1 (0, 0, 100, 100);
paintdc.PlayMetaFile(hmf, rect1);
DeleteEnhMetaFile(hmf);
AfxMessageBox("close");
}
I am trying to calculate this ratio that would display a proper 100*100 pixels bitmap on the screen.
I have tried to play with different mappings, including by applying mappings to the metafile. On my PC at least, the correct ratio would be around 39, but using a hard coded value is not satisfactory as it does not give the same result on someone else's PC.
Elrond
A chess genius is a human being who focuses vast, little-understood mental gifts and labors on an ultimately trivial human enterprise.
-- George Steiner
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|