How to crop Metafile

404 Views Asked by At

I'm working with MetaFile. Is there any way to crop a metafile to zoom a specific part?

I'm thinking of redrawing it on a larger bitmap then crop that image, but I know this is not ideal.

1

There are 1 best solutions below

0
On

When drawing to a Graphics surface, i.e. when drawing to a Bitmap, you can easily crop using one of the overloads of the DrawImage() method. Here is an example where only the lower right quarter of the metafile is drawn to the bitmap:

Metafile metafile = ...;

Bitmap target = new Bitmap(1000, 1000);

using (Graphics g = Graphics.FromImage(target))
{
    g.DrawImage(metafile, -1000, -1000, 2000, 2000);
    g.Flush();
}