int iHeightPels = GetDeviceCaps(hdcMain, VERTRES);
Gdiplus::RectF rcBoundsX(0, 0,
(Gdiplus::REAL)width, (Gdiplus::REAL)height);
rcBoundsX.Y *= iHeightMM * 100 / iHeightPels;
rcBoundsX.X *= iWidthMM * 100 / iWidthPels;
rcBoundsX.Width *= iWidthMM * 100 / iWidthPels;
rcBoundsX.Height *= iHeightMM * 100 / iHeightPels;
Gdiplus::Metafile emf(T2W(m_fileName), hdcMain, rcBoundsX,
Gdiplus::MetafileFrameUnitGdi, Gdiplus::EmfTypeEmfPlusDual,
L"[TODO: Description]");
//获得图片
Gdiplus::Graphics g(&emf);
HDC imgDc = g.GetHDC();
// For unknown reasons Internet Explorer will sometimes
// fail to draw glyphs for certain characters here even
// though they are rendered in Internet Explorer itself.
// On other pages, Internet Explorer will simply render
// a single bitmap into the emf which isn't really what
// this should do. I've no idea how to fix that however.
hr = spViewObject->Draw(DVASPECT_CONTENT, -1, NULL, NULL, imgDc,
imgDc, &rcBounds, NULL, NULL, 0);
g.ReleaseHDC(imgDc);
ReleaseDC(hdcMain);
return false;
}
CImage image;
// TODO: check return value;
// TODO: somehow enable alpha
image.Create(width, height, 24);
HDC imgDc = image.GetDC();
hr = spViewObject->Draw(DVASPECT_CONTENT, -1, NULL, NULL, imgDc,
imgDc, &rcBounds, NULL, NULL, 0);
image.ReleaseDC(); www.2cto.com
//保存
if (SUCCEEDED(hr))
hr = image.Save(m_fileName);
return false;
}
源码下载