C# 如何从Microsoft Word文件中将嵌入图像转换为PNG格式?

C# 如何从Microsoft Word文件中将嵌入图像转换为PNG格式?,c#,ms-office,aspose,C#,Ms Office,Aspose,我一直在使用以下代码从word文件中提取图像: Document doc = new Document(MyDir + "Image.SampleImages.doc"); NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true, false); int imageIndex = 0; foreach (Shape shape in shapes) { i

我一直在使用以下代码从word文件中提取图像:

Document doc = new Document(MyDir + "Image.SampleImages.doc");

    NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true, false);
    int imageIndex = 0;           
    foreach (Shape shape in shapes)
    {
        if (shape.HasImage)
        {
            string imageFileName = string.Format(
                "Image.ExportImages.{0} Out{1}", imageIndex, FileFormatUtil.ImageTypeToExtension(shape.ImageData.ImageType));
            shape.ImageData.Save(MyDir + imageFileName);
            imageIndex++;
        }
    }

图像的输出格式是.emf,而我想要的是.png。请告诉我如何使用上述代码获取“PNG”格式而不是EMF。

这是因为Aspose ImageData的ImageType属性是图像的原始格式,在保存过程中不会更改。相反,您应该从ImageData(使用ToImage)获取图像对象,然后将其保存为所需格式。即:

        shape.ImageData.ToImage().Save(MyDir + imageIndex.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png);

您应该提到,您正在使用: