This works on Linux without Windows GDI. For EMFs with text, install the fonts the file uses or supply them through MetafileFontOptions. The sample badge.emf in the zip draws a blue rectangle.
dotnet add package RecursiveAI.OneImage.MetafileRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using OneImage; using OneImage.Metafile; var config = new ImageConfiguration() .Add(MetafileFormat.Instance); var load = new LoadOptions { Configuration = config }; Image.Load("badge.emf", load) .Resize(width: 320) .Save("badge.png");
Unzip the example, then dotnet run.
Writes badge.png, a 320×160 image.
The full program
The download also opens the PNG it wrote and prints its dimensions. A file with a bad metafile header throws ImageFormatException.
using OneImage; using OneImage.Metafile; var config = new ImageConfiguration() .Add(MetafileFormat.Instance); var load = new LoadOptions { Configuration = config }; Image.Load("badge.emf", load) .Resize(width: 320) .Save("badge.png"); var png = Image.Load("badge.png"); Console.WriteLine($"badge.png: {png.Width} × {png.Height}");
badge.png: 320 × 160Variations
Use the EMF’s natural pixel size. Replace the load–resize–save chain with this line; the rest of the program stays the same.
Image.Load("badge.emf", load).Save("badge.png");badge.png: 160 × 80Related recipes
The short answer
Install RecursiveAI.OneImage.Metafile, add MetafileFormat.Instance to the ImageConfiguration passed into Image.Load, then save to a .png path. A width alone keeps the aspect ratio: the 160×80 sample renders to 320×160 when you request a width of 320.
What is the EMF image format?
EMF stands for Enhanced Metafile, a Windows graphics format. Instead of storing one final grid of pixels like a PNG, it stores records that describe drawing operations. Those can include paths, text and embedded bitmaps. The PNG captures the result at one chosen resolution; it no longer contains the original drawing commands. Keep the EMF if you’ll need other sizes later.
EMF and WMF are separate formats even though both are Windows metafiles. Register MetafileFormat for EMF. A WmfFormat registration is separate and is only needed to load WMF. OneImage also interprets EMF+ records, including those in dual files; see the metafile docs for which commands are supported.
How do you convert an EMF file to PNG at the right size?
Use the EMF’s natural size if you need the reference dimensions from its header. The sample’s reference canvas is 160×80. Otherwise, choose a width in pixels before saving. The metafile docs say “Resize/Thumbnail draw at the final size.” This means the example draws at 320 pixels wide rather than enlarging an intermediate 160-pixel PNG. Not every mark scales the same way: a cosmetic pen stays one output pixel wide; a geometric pen scales with the picture.
The default background is transparent and anti-aliasing is on. Your input can still paint its own background. A substitute font can change how text looks. Some records are unsupported and skipped with a diagnostic, so a successful PNG write doesn’t establish that every mark in the original was drawn. The record gaps in the metafile docs list cases to check if something is missing.