How to set bounds Graphics when using Metafile?

488 views Asked by At

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?

0

There are 0 answers