EMF的问题,请指点一下?

ggff1974 2003-10-15 11:44:48
我用VC开发的程序,需要存Emf文件,但是生成的Emf文件的图形总在整幅图的最左上角的一小块区域,不能充满整个图,请指点一下?
...全文
31 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
mct1025 2003-10-16
  • 打赏
  • 举报
回复
可能是SetMapMode的原因

参考一下这段程序,不用设置SetMapMode,metafile中还是以像素为单位
PlayEnhMetaFile时,也不要设置SetMapMode
HDC hdcRef = ::GetDC(this->m_hWnd);

// Determine the picture frame dimensions.
// iWidthMM is the display width in millimeters.
// iHeightMM is the display height in millimeters.
// iWidthPels is the display width in pixels.
// iHeightPels is the display height in pixels
int iWidthMM = GetDeviceCaps(hdcRef, HORZSIZE);
int iHeightMM = GetDeviceCaps(hdcRef, VERTSIZE);
int iWidthPels = GetDeviceCaps(hdcRef, HORZRES);
int iHeightPels = GetDeviceCaps(hdcRef, VERTRES);

// Retrieve the coordinates of the client
// rectangle, in pixels.
RECT rect;
::GetClientRect(this->m_hWnd, &rect);

// Convert client coordinates to .01-mm units.
// Use iWidthMM, iWidthPels, iHeightMM, and
// iHeightPels to determine the number of
// .01-millimeter units per pixel in the x-
// and y-directions.
rect.left = (rect.left * iWidthMM * 100)/iWidthPels;
rect.top = (rect.top * iHeightMM * 100)/iHeightPels;
rect.right = (rect.right * iWidthMM * 100)/iWidthPels;
rect.bottom = (rect.bottom * iHeightMM * 100)/iHeightPels;

char szFileName[] = "C:\\t.wmf";
char szDescription[] = "metafile test";
// Create the metafile device context.

HDC hdcMeta = ::CreateEnhMetaFile(hdcRef,
szFileName,
&rect, szDescription);

if (!hdcMeta)
return;
char sztext[] = "metafile test";
::TextOut(hdcMeta,0,0,sztext,strlen(sztext));
::TextOut(hdcMeta,20,20,sztext,strlen(sztext));
::TextOut(hdcMeta,40,40,sztext,strlen(sztext));
::TextOut(hdcMeta,60,60,sztext,strlen(sztext));

::Rectangle(hdcMeta,80,80,200,200);

HENHMETAFILE hmf;
hmf = ::CloseEnhMetaFile(hdcMeta);
::DeleteEnhMetaFile(hmf);

// Release the reference device context.
::ReleaseDC(this->m_hWnd, hdcRef);
ggff1974 2003-10-16
  • 打赏
  • 举报
回复
//图形的逻辑坐标被设置为每个逻辑单位0.1mm
CMetaFileDC* pMetaFileDC;
HMETAFILE hMetaFile;
HENHMETAFILE hHenMetaFile;
pMetaFileDC=new CMetaFileDC();
CMetaFileDC * pDC=pMetaFileDC;

CClientDC dc(this);

CSize size = GetDocument()->GetSize();//得到图形的大小,设备坐标单位
CRect total_rect(0,0,size.cx,size.cy);

ClientToDoc(total_rect);//转化为逻辑坐标,每个逻辑单位是0.1mm
total_rect.right=total_rect.right*10;
total_rect.bottom=total_rect.bottom*10;//按照0.01mm的大小设置图形大小

pDC->CreateEnhanced(NULL,theCFileDialog.m_ofn.lpstrFile,&total_rect,"MultiWellContrast" );

pDC->SetAttribDC(dc.m_hAttribDC);

pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(30,30);
pDC->SetWindowOrg(0,0);
pDC->SetViewportExt(pDC->GetDeviceCaps(LOGPIXELSX),pDC->GetDeviceCaps(LOGPIXELSY));
pDC->SetViewportOrg(0,0);

CBrush fill(BACKGROUND_COLOR);
pDC->FillRect(total_rect,&fill);

CMainDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->Draw(pDC, this);//绘制图形
hHenMetaFile = pDC->CloseEnhanced();
hMetaFile = pDC->Close();
DeleteMetaFile(hMetaFile);
DeleteEnhMetaFile(hHenMetaFile);

pDC->Detach();
ReleaseDC(pDC);
mct1025 2003-10-15
  • 打赏
  • 举报
回复
把保存代码贴出来看看

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧