如何使用 MS Open XML SDK 检索一些图像数据和格式?
这是 如何使用 MS Open XML SDK 从 .pptx 文件检索图像?
如何检索:
- 来自 DocumentFormat.OpenXml.Presentation.Picture 对象的图像数据?
- 图像名称和/或类型?
例如,如下:
using (var doc = PresentationDocument.Open(pptx_filename, false)) {
var presentation = doc.PresentationPart.Presentation;
foreach (SlideId slide_id in presentation.SlideIdList) {
SlidePart slide_part = doc.PresentationPart.GetPartById(slide_id.RelationshipId) as SlidePart;
if (slide_part == null || slide_part.Slide == null)
continue;
Slide slide = slide_part.Slide;
foreach (var pic in slide.Descendants<Picture>()) {
// how can one obtain the pic format and image data?
}
}
}
我意识到我有点在这里寻求现成的答案,但我只是无法在任何地方找到足够好的文档来自己解决这个问题。
This is a follow-up question to How can I retrieve images from a .pptx file using MS Open XML SDK?
How can I retrieve:
- The image data from a DocumentFormat.OpenXml.Presentation.Picture object?
- The image name and/or type?
in, say, the following:
using (var doc = PresentationDocument.Open(pptx_filename, false)) {
var presentation = doc.PresentationPart.Presentation;
foreach (SlideId slide_id in presentation.SlideIdList) {
SlidePart slide_part = doc.PresentationPart.GetPartById(slide_id.RelationshipId) as SlidePart;
if (slide_part == null || slide_part.Slide == null)
continue;
Slide slide = slide_part.Slide;
foreach (var pic in slide.Descendants<Picture>()) {
// how can one obtain the pic format and image data?
}
}
}
I realize that I'm kinda asking for out-of-the-oven answers here, but I just can't find good enough docs anywhere to figure it out on my own.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,获取对图片的 ImagePart 的引用。 ImagePart 类提供您正在查找的信息。下面是一个代码示例:
出于同样的原因,您还可以使用以下代码迭代 SlidePart 的所有 ImagePart:
希望这会有所帮助。
First, obtain a reference to the ImagePart of your Picture. The ImagePart class provides the information you are looking for. Here is a code sample:
By the same token you could also iterate over all ImagePart's of a SlidePart using the following code:
Hope, this helps.