On Windows, you could do something like the following.
Regards,
Julian
static void wxHIMETRICToPixel(LONG *x, LONG *y)
{
*x = (*x) * 96 / 2540;
*y = (*y) * 96 / 2540;
}
// This function is more accurate and consistent than the wxWidgets one
static wxSize wxEnhMetaFileGetSize(wxEnhMetaFile& mf)
{
wxSize size = wxDefaultSize;
if ( mf.Ok() )
{
ENHMETAHEADER hdr;
if (
!::GetEnhMetaFileHeader(((HENHMETAFILE)mf.GetHENHMETAFILE()),
sizeof(hdr), &hdr) )
{
wxLogLastError(_T("GetEnhMetaFileHeader"));
}
else
{
// the width and height are in HIMETRIC (0.01mm) units,
transform
// them to pixels
LONG w = hdr.rclFrame.right,
h = hdr.rclFrame.bottom;
wxHIMETRICToPixel(&w, &h);
size.x = w;
size.y = h;
}
}
return size;
}
#endif
// Image is simply read in into hash map keyed by its name
if (FileUtilities::GetExtension(name).Lower() == wxT("wmf") ||
FileUtilities::GetExtension(name).Lower() == wxT("emf"))
{
#ifdef __WXMSW__
if (wxFileExists(filename))
{
wxLogNull log;
wxEnhMetaFile* enhMetafile = new wxEnhMetaFile(filename);
if (enhMetafile->IsOk())
{
//wxSize sz = enhMetafile->GetSize();
wxSize sz = wxEnhMetaFileGetSize(*enhMetafile);
if (sz.x != 0 && sz.y != 0)
{
wxRect rect(0, 0, sz.x, sz.y);
wxBitmap bitmap(sz.x, sz.y);
wxMemoryDC dc;
dc.SelectObject(bitmap);
dc.SetBackground(*wxWHITE_BRUSH);
dc.Clear();
if (enhMetafile->Play(& dc, & rect))
{
dc.SelectObject(wxNullBitmap);
if (bitmap.IsOk())
{
wxImage image = bitmap.ConvertToImage();
...
delete enhMetafile;
}
}
}
}
delete enhMetafile;
}