Playing a metafile

To show a metafile

metaFile = new Metafile(path);
e.Graphics.DrawImage(metaFile, clientRect);    
metaFile.Dispose(); 
metaFile = null;

Although this code shows the metafile, you may notice strange scaling problems. The metafile is being drawn ignoring the aspect ratio!

You can get the original size using the following code

MetafileHeader header = metaFile.GetMetafileHeader();
Rect metaRect = header.Bounds;

Use the metaRect to adjust the clientRect to get the same aspect ratio and the scaling will be fine.

Lastest update in February 2012, inital post in February 2012

Write a comment

I appreciate comments, suggestions, compliments etc. Unfortunately I have no time to reply to them. Useful input will be used for sure!