简体   繁体   English

如何在word文档中插入图片并使用openxml保持原始大小

[英]How to insert an image in a word document and maintain the original size using openxml

I tried do like this Inserting Image into DocX using OpenXML and setting the size but I not found the reference of "new BitmapImage"我尝试这样做使用 OpenXML 将图像插入 DocX 并设置大小,但我没有找到“new BitmapImage”的参考

I'am using framework .NET 4.5 on Visual Studio 2013 in ASP.NET MVC Application我在 ASP.NET MVC 应用程序中的 Visual Studio 2013 上使用框架 .NET 4.5

Have a look at this : MSDN Basically you have to use this: Notice the ImagePartType看看这个: MSDN基本上你必须使用这个:注意 ImagePartType

MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart;
ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
using (FileStream stream = new FileStream(fileName, FileMode.Open))
{
   imagePart.FeedData(stream);
}
AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM