Image conversion issue with Linux (2)

Hi.

I’m converting a VSD document to VSDX, am experiencing an issue with certain EMF images when converting them to PNG, using shape.ToImage method.

This issue is a follow-up on issue Image conversion issue with Linux.

The fix there is working on most charts, but I’ve found others where it isn’t.

I’ve attached two of those charts (both their original VSD, and the converted VSDX which contain PNG images instead of EMF).

charts.zip (4.5 MB)

You can use the same program as before to reproduce the issue for EMF images.
EMF2PNG_Aspose.zip
but also add this, as part of the previous fix as you suggested:

pngs.EmfRenderSetting = Aspose.Diagram.EmfRenderSetting.EmfPlusPrefer;

The archive contains two pairs of charts, both of them outputs blank PNGs for EMFs.

Would like your help resolving this issue.

Kind regards,
Swalih.

@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.


:one: 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.


:two: 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.


:three: 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.

:four: 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:

  1. 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.
  2. 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.


:five: 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.


:books: Useful links


Next steps

  1. Upgrade to the latest Aspose.Diagram version (if not already).
  2. Verify libgdiplus is installed and up‑to‑date.
  3. 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

@SWALIH
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): DIAGRAMNET-53808

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@SWALIH
We ran your project on Linux using the latest version (25.9) and obtained the correct PNG images. Also, directly saving a VSD file as a VSDX produces a proper VSDX file (which contains EMF images instead of PNG). Please try the latest version.
If you still encounter this issue, please let us know how you are generating the VSDX file.
Please find attached the output file for your reference.
vsdxandpng.zip (687.8 KB)

Hi.
Thank you for your response. I found a misconfiguration in how I ran it before. I’ve run the test again, with 25.9, and attached it below.

EMF2PNG_Aspose_25.9.7z (1.6 MB)

I see that document d16730231c9747v64002 that I shared before is indeed working as expected as you’ve shown, when converting EMF to PNG.

However, I still see a problem for the document d4711991c82963v127001.vsdx. There are a lot of EMF images in it, but it fails while converting the fourth EMF image which appears to save an empty/corrupted image, running on Docker.

I’ve updated the code focused on just this chart along with the Visio document, and saving all the conversions.

Please have a look at this, with the attached project.

Kind regards,
Swalih.

@SWALIH
Thank you for your suggestion. We will look further into it.