We are using Aspose.Diagram for .NET version 24.12.0 in a C#-application which is used on Windows platforms and Linux platforms.
We have an issue with saving the shapes of a Visio-document in the master from emf to png-format.
The resulted png-files are all blank and when saving them to emf the result is as expected.
Hereby the sample code we are using:
ForeignType[] expectedForeignTypes = [ForeignType.Metafile, ForeignType.EnhMetafile];
List<Aspose.Diagram.Shape> emfShapes = new();
using (Diagram diagram = new Diagram("bpmn_d5926266c2198v0.vsdx", LoadFileFormat.Vsdx))
{
diagram.Metric = BOOL.False; // Use English units
diagram.RemoveHiddenInformation((int)(RemoveHiddenInfoItem.PersonalInfo | RemoveHiddenInfoItem.Shapes));
foreach (Master master in diagram.Masters)
{
foreach (Shape shape in master.Shapes)
{
if (shape.Type == TypeValue.Foreign && expectedForeignTypes.Contains(shape.ForeignData.ForeignType))
{
emfShapes.Add(shape);
}
foreach (Shape shape2 in shape.Shapes)
{
if (shape2.Type == TypeValue.Foreign && expectedForeignTypes.Contains(shape2.ForeignData.ForeignType))
{
emfShapes.Add(shape2);
}
}
}
}
ImageSaveOptions imageSaveOptionsPNG = new(SaveFileFormat.Png) { InterpolationMode = InterpolationMode.Default, CompositingQuality = CompositingQuality.HighQuality };
ImageSaveOptions imageSaveOptionsEMF = new(SaveFileFormat.Emf) { InterpolationMode = InterpolationMode.Default, CompositingQuality = CompositingQuality.HighQuality };
Console.WriteLine($"EMF Shapes count: {emfShapes.Count}");
int index = 0;
foreach (Shape shape in emfShapes)
{
shape.ToImage($"emf2png{index}.png", imageSaveOptionsPNG);
shape.ToImage($"emf2png{index}.emf", imageSaveOptionsEMF);
index++;
}
}
It seems you are encountering an issue where the images generated from EMF shapes in your Visio document are coming out blank when saved as PNG files. This can happen due to various reasons related to how the shapes are processed or rendered.
Here are a few suggestions to troubleshoot and potentially resolve the issue:
Check Shape Properties: Ensure that the shapes you are trying to convert actually contain visible content. Sometimes, shapes may have properties that render them invisible or may not have any fill or stroke.
Update Aspose.Diagram Version: You are using version 24.12.0 of Aspose.Diagram for .NET. It might be beneficial to check if there are any updates or patches available for the library that address issues related to image rendering. Newer versions often include bug fixes and improvements.
Use Different ImageSaveOptions: You are currently using InterpolationMode.Default and CompositingQuality.HighQuality. Try experimenting with different settings for ImageSaveOptions to see if that affects the output. For example, you might want to try InterpolationMode.Bilinear or CompositingQuality.Default.
Test with Different Shapes: If possible, try to isolate the issue by testing with different shapes or a simpler Visio document. This can help determine if the problem is specific to certain shapes or the document itself.
Export to Other Formats: Since you mentioned that saving to EMF works as expected, consider exporting to other formats (like BMP) to see if the issue persists across different formats. This can help identify if the problem is specific to PNG conversion.
Check for Hidden Information: You are already removing hidden information from the diagram. Ensure that this process is not inadvertently affecting the shapes you are trying to render.
If these suggestions do not resolve the issue, you may want to reach out to Aspose support with detailed information about the shapes and the specific Visio document you are working with. Providing a minimal reproducible example can also help in diagnosing the problem more effectively.
Feel free to ask if you have any further questions or need additional assistance!
@tkn1967
Thanks for the template file and output.
After an initial testing, I am able to reproduce the issue as you mentioned by using your template file.
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-53656
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.
Hereby some additional information.
It seems that the first save of the shape goes wrong.
When you switch the shape.ToImage-lines in the example the save to emf goes wrong.
Hopefully you can do something with this information.