1

In our application it's possible to create images in different fileformats, like PNG, BMP, JPEG etc. Now I'm currently investigating the possibility to create Metafile images (.emf). With our Charts I can get this to work, because we're using the microsoft Charting library and with this it's possible to export a chart in .emf format.

(ChartImageFormat.EmfDual);

We also create maps, and this is where it goes wrong. When I create the graphics using a Bitmap, the graphic element has a useful visibleClipbounds.

var image = new Bitmap(Width, Height);

using (var graphics = Graphics.FromImage(image))
{
 //visibleClipbounds: {X = 0 Y = 0 Width = 1241 Height = 774}
}

When I use a metafile to create the graphics object, the VisibleClipbounds is enormous...

Graphics refG = Graphics.FromHwndInternal(IntPtr.Zero);
IntPtr refGrap = refG.GetHdc();
Metafile m = new Metafile(refGrap, EmfType.EmfPlusDual, "...");
using (var graphics = Graphics.FromImage(m))
{
//visibleClipbounds: {X = -4194304 Y = -4194304 Width = 8388608 Height = 8388608}
}

Is there a way I can create a graphics element using the metafile, but keep the visibleClipbounds the same way as when I create a graphics element using a Bitmap?

Vincent Hogendoorn
  • 700
  • 1
  • 7
  • 23
  • 3
    The point of a Metafile is to *not* have a fixed size. Meant to be freely scalable, the essential difference between vector graphics and bitmap graphics. Be sure to never use Graphics.DrawImage(), that defeats the point of using a Metafile. Nevertheless, when you generate an EMF then you should include a size *recommendation*. Use a constructor overload that accepts a RectangleF. – Hans Passant Jul 07 '16 at 15:39

0 Answers0