---
title: "Convert EMF to PNG on Linux in C#"
url: https://recursiveai.org/oneimage/cookbook/convert-emf-to-png/
description: "Convert EMF to PNG on Linux in C#. Register OneImage’s managed metafile reader, choose the output width, and rasterize a local file without Windows GDI."
version: "1.11.2"
---

# Convert EMF to PNG on Linux in C#

**OneImage** is a free, open-source image library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneImage.Metafile) · [GitHub](https://github.com/recursive-ai-oss/oneimage-csharp) · [Docs](https://recursiveai.org/oneimage/docs/) · [Download example (.zip)](https://recursiveai.org/oneimage/cookbook/convert-emf-to-png/convert-emf-to-png.zip)

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.

```shell
dotnet add package RecursiveAI.OneImage.Metafile
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
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](https://recursiveai.org/oneimage/cookbook/convert-emf-to-png/convert-emf-to-png.zip), 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`.

```csharp
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}");
```

```text
badge.png: 320 × 160
```

## Variations

**Use the EMF’s natural pixel size.** Replace the load–resize–save chain with this line; the rest of the program stays the same.

```csharp
Image.Load("badge.emf", load).Save("badge.png");
```

```text
badge.png: 160 × 80
```

## Related recipes

- [Convert SVG to PNG](https://recursiveai.org/oneimage/cookbook/svg-to-png/)
- [Set the PNG compression level](https://recursiveai.org/oneimage/cookbook/set-png-compression-level/)

## 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](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-emf/), 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](https://recursiveai.org/oneimage/docs/metafile/) 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](https://recursiveai.org/oneimage/docs/metafile/) 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](https://recursiveai.org/oneimage/docs/metafile/#gaps-in-gdi-records-each-produces-a-diagnostic) list cases to check if something is missing.
