我正在尝试从 docx 文件中导出图像。如何将来自 Shape 对象的 EncodedPackage 转换为图像?
我的代码示例:
DocumentFormat.OpenXml.Vml.Shape shape = imageElement.Descendants<DocumentFormat.OpenXml.Vml.Shape>().FirstOrDefault();
byte[] bytes = System.Convert.FromBase64String(shape.EncodedPackage.Value.Replace("\n", ""));
System.Drawing.Image image;
using (MemoryStream ms = new MemoryStream(bytes))
{
image = System.Drawing.Image.FromStream(ms);
}
image.Save(fileName);