@SWALIH
Hello Swalih,
Thank you for the detailed information and the sample files.
I’ve reviewed the scenario and will walk you through a few steps that normally resolve EMF‑to‑PNG conversion issues on Linux with Aspose.Diagram.
Verify the library version
The EMF rendering engine was improved in later releases. Please make sure you are using the latest stable version (at the time of writing 23.12).
If you are on an older build, upgrade the NuGet package:
dotnet add package Aspose.Diagram --version 23.12.0
After the upgrade, re‑run the conversion and let us know if the PNGs are still blank.
Confirm the Linux graphics dependencies
Aspose.Diagram relies on libgdiplus
for GDI+ emulation. On most Linux distributions the package must be at least 6.0 and fully functional.
# Ubuntu / Debian
sudo apt-get update
sudo apt-get install -y libgdiplus
# (optional) create a symlink for mono
sudo ln -s /usr/lib/libgdiplus.so /usr/lib/mono/4.5/libgdiplus.dll
After installing / updating libgdiplus
, restart your application and test again.
Apply the recommended EMF‑plus rendering setting
You already set
pngs.EmfRenderSetting = Aspose.Diagram.EmfRenderSetting.EmfPlusPrefer;
That is correct. For completeness, here is a minimal, reproducible snippet that works on Linux with the latest package:
using Aspose.Diagram;
using System.IO;
class Program
{
static void Main()
{
// Load the VSD file
Diagram diagram = new Diagram(@"chart1.vsd");
// Save the whole diagram as VSDX (optional)
diagram.Save(@"chart1.vsdx", SaveFileFormat.VSDX);
// Iterate over all shapes that contain an EMF image
foreach (Page page in diagram.Pages)
{
foreach (Shape shape in page.Shapes)
{
if (shape.Image != null && shape.Image.Type == ImageType.Emf)
{
// Render the shape to PNG
using (MemoryStream pngStream = new MemoryStream())
{
// Set the rendering option
ImageSaveOptions pngs = new ImageSaveOptions(SaveFileFormat.PNG);
pngs.EmfRenderSetting = EmfRenderSetting.EmfPlusPrefer;
// Render the shape
shape.ToImage(pngStream, pngs);
// Write PNG to disk for verification
File.WriteAllBytes($"{shape.ID}_image.png", pngStream.ToArray());
}
}
}
}
}
}
Key points
ImageSaveOptions
is used instead of the older overload that only takes a Stream
.
- The
EmfRenderSetting
flag is applied before calling ToImage
.
- The
shape.Image.Type
check guarantees we only process EMF shapes.
Check the EMF content itself
Occasionally an EMF file can contain EMF+ v1.1 features that need the EmfPlusPrefer
flag (which you already set). However, if the EMF was generated by an older Visio version or a third‑party exporter, the image may be stored as a metafile preview rather than a full raster. In that case:
- Open the original VSD in Visio (or any viewer that can display the shape) and export the shape to PNG manually. Compare the exported PNG size with the one produced by Aspose – if the manual export is non‑blank, the EMF stream is valid.
- If the manual export also yields a blank image, the EMF data itself is corrupted; Aspose cannot render it.
If step 1 shows a valid PNG while Aspose still returns a blank image, please capture the exact EMF byte array (e.g., File.WriteAllBytes("raw.emf", shape.Image.Data)
) and attach it to a follow‑up post. That will let us reproduce the problem in a controlled environment.
Provide additional environment details (if needed)
If the above steps still produce blank PNGs, kindly share the following information so we can dig deeper:
Item |
What to provide |
Aspose.Diagram version |
e.g., 23.12.0 |
OS distribution & version |
e.g., Ubuntu 22.04, Alpine 3.18 |
.NET runtime |
.NET 6 / .NET 7 / .NET Core 3.1 |
libgdiplus version |
`dpkg -l |
Sample EMF bytes |
Attach the raw EMF file extracted from the shape |
Exact code snippet |
(the one you are running) |
With those details we can reproduce the scenario on our Linux test farm and provide a precise fix.
Useful links
Next steps
- Upgrade to the latest Aspose.Diagram version (if not already).
- Verify
libgdiplus
is installed and up‑to‑date.
- Re‑run the conversion using the snippet above.
If the PNGs remain blank, please reply with the environment details and, if possible, the raw EMF stream from one of the problematic shapes. We’ll investigate further and work toward a resolution.
Looking forward to hearing back from you.
Kind regards,
Aspose Support Team