We're sorry Aspose doesn't work properply without JavaScript enabled.

Can I keep the transparency information when extracting emf Image?

I use ShapeRenderer to convert emf images to png images for my docx documents. But it seemed that transparency information is lost after converting to png files. The background is turned to pure white. Can I keep the transparency information after saving to png images?

@dajyaretakuya2 Could you please attach your document here for testing? We will check the issue and provide you more information.

The only picture with transparent background in the docx file is attached. emf_test.docx (19.4 KB)

@dajyaretakuya2 Thank you for additional information. You can achieve this by using empty color as a background color. For example see the following code.
In .NET:

Document doc = new Document(@"C:\Temp\in.docx");

Shape s = (Shape)doc.GetChild(NodeType.Shape, 0, true);

ImageSaveOptions opt = new ImageSaveOptions(SaveFormat.Png);
opt.PaperColor = Color.Empty;

s.GetShapeRenderer().Save(@"C:\Temp\out.png", opt);


In java:

Document doc = new Document("C:\\Temp\\in.docx");

Shape s = (Shape)doc.getChild(NodeType.SHAPE, 0, true);

ImageSaveOptions opt = new ImageSaveOptions(SaveFormat.PNG);
// Use transparent white as a background color.
opt.setPaperColor(new Color(255,255,255,0));

s.getShapeRenderer().save("C:\\Temp\\out.png", opt);


Ah yes. I did not see the ImageSaveOptions usage carefully. Finally I got the correct transparent png. Thanks very much!

1 Like