我是C++和OpenGL的新手。有人曾經寫過這個C++應用程序(基於Linux),我必須調整它。將CDC窗口的內容導出到EMF文件
基本上在這個應用程序中,有一個包含圖的窗口。現在這個窗口支持將圖輸出到位圖(tga,jpg和bmp)的功能。我們想添加另一個功能來將劇情的內容保存爲增強元文件。
我設法得到CDC設備處理程序,並使用它的HDC創建一個空的EMF,其寬度/高度與繪圖相同,但是我不知道如何將繪圖的CONTENT遷移到EMF文件。有沒有任何代碼可以做到這一點?
我用來創建空的EMF文件的代碼如下。不要理解任何想法或幫助!
CDC* dc = pWnd->GetDC();
HDC hdcRef;
hdcRef = dc->GetSafeHdc();
CRect rect;
pWnd->GetClientRect(rect);
// Convert client coordinates to .01-mm units.
// Use iWidthMM, iWidthPels, iHeightMM, and
int iWidthMM = GetDeviceCaps (hdcRef, HORZSIZE);
int iHeightMM = GetDeviceCaps (hdcRef, VERTSIZE);
int iWidthPels = GetDeviceCaps (hdcRef, HORZRES);
int iHeightPels = GetDeviceCaps (hdcRef, VERTRES);
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;
//::SetMapMode(hdcRef, MM_HIMETRIC);
HDC hdcMeta = CreateEnhMetaFile(hdcRef, "C:\\temp\\testEMF.emf", &rect, "Example metafile\0");
if (!hdcMeta)
GenAppWarningMsg("CreateEnhMetaFile", "Error");
// Set the device context back to its original state.
SetMapMode(hdcMeta, MM_ANISOTROPIC);
::ReleaseDC(NULL, hdcRef);
HENHMETAFILE meta = CloseEnhMetaFile (hdcMeta);
要生成EMF,理想情況下,您不會保存位圖,而是保存單個線條,點等,以生成繪圖,以便可以高質量地渲染結果。 – Bryan