将字节数组中的图像插入 OpenXML CustomXmlBlock
我正在使用一个模板文档,该文档使用 CustomXmlBlocks 作为占位符来放置表格和其他信息。我需要能够以某种方式将图像放入其中一个块中......即使它首先放入运行中。
图像以字节数组(最终为 .bmp 格式)的形式从数据集中的数据库返回。
我试图做这样的事情只是为了看看我是否可以让图像显示在文档中,但无济于事:
ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Bmp);
MemoryStream imageStream = new MemoryStream(imgData); //imgData is the byte array
imagePart.FeedData(imageStream);
我一直认为必须有一种简单的方法来获取字节流并将其放入文档,但我在任何地方都找不到任何示例。我现在需要对该 imagePart 执行其他操作吗?
I'm working with a template document that uses CustomXmlBlocks as placeholders to place tables and other information. I need to be able to place an image into one of these blocks somehow... even if it is placed into a run first.
The images come back from the database in a dataset as a byte array (.bmp format ultimately).
I was trying to do something like this just to see if I could even get the image to show up in the document but to no avail:
ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Bmp);
MemoryStream imageStream = new MemoryStream(imgData); //imgData is the byte array
imagePart.FeedData(imageStream);
I keep thinking there has to be an easy way to just take the byte stream and place it into the document but I haven't been able to find any examples anywhere. Do I now need to do something else with that imagePart?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您确实需要对 imagePart 做一些其他的事情;您需要将图像结构(旧的 VML w:pict 或图形)添加到引用它的主文档部分。请参阅如何:将图片插入字处理文档
或者,您也可以可以将其添加到 CustomXML 部分,并使用图片内容控件将其吸收。
Yes, you do need to do something else with the imagePart; you need to add an image structure (either an old VML w:pict or a graphic) to your main document part which refers to it. See How to: Insert a Picture into a Word Processing Document
Alternatively, you can add it to a CustomXML part, and suck it in using a picture content control.