C# 获取要添加到DOCX的图像详细信息
我使用这里的WordprocessingDocument方法(Open XML)将图像添加到DOCX文件中 我可以添加图像,但大小不正确C# 获取要添加到DOCX的图像详细信息,c#,c#-4.0,C#,C# 4.0,我使用这里的WordprocessingDocument方法(Open XML)将图像添加到DOCX文件中 我可以添加图像,但大小不正确 MainDocumentPart mainPart = doc.MainDocumentPart; ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); using (System.IO.FileStream stream = new System.IO.FileStream(file
MainDocumentPart mainPart = doc.MainDocumentPart;
ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
using (System.IO.FileStream stream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
imagePart.FeedData(stream);
}
return AddImageToBody(doc, mainPart.GetIdOfPart(imagePart), fileName);
private static Drawing AddImageToBody(WordprocessingDocument wordDoc, string relationshipId, string filename)
{
long imageWidthEMU = 1900000;
long imageHeightEMU = 350000;
double imageWidthInInches = imageWidthEMU / 914400.0;
double imageHeightInInches = imageHeightEMU / 914400.0;
new DW.Extent();
//Define the reference of the image.
var element =
new Drawing(
new DW.Inline(
new DW.Extent() { Cx = imageWidthEMU, Cy = imageHeightEMU },
如您所见,您可以手动指定尺寸(长度+宽度)。我无法动态获取它们。如何获得传递给此代码的正确图像大小
谢谢。您的问题已在此处解决:
没有办法通过xml文件中的指令来解决这个问题。OOXML只提供了
和
选项。您的问题在这里得到了解决:
没有办法通过xml文件中的指令来解决这个问题。OOXML只提供
和
选项