原創|其它|編輯:郝浩|2012-10-17 17:14:15.000|閱讀 4128 次
概述:本文使用示例的方式解釋了如何使用Aspose.Words從文檔中提取圖像。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
本文使用示例的方式解釋了如何使用Aspose.Words從文檔中提取圖像。
從文檔中提取所有圖像或特定類型的圖像,步驟如下:
1 使用Document.GetChildNodes method方法選擇所有Shape節點。
2 循環訪問節點集合。
3 檢查Shape.HasImage布爾屬性。
4 使用Shape.ImageData屬性提取圖像的數據。
5 保存圖像數據到一個文件。
Java
public void extractImagesToFiles() throws Exception { Document doc = new Document(getMyDir() + "Image.SampleImages.doc"); NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true); int imageIndex = 0; for (Shape shape : (Iterable<Shape>) shapes) { if (shape.hasImage()) { String imageFileName = java.text.MessageFormat.format( "Image.ExportImages.{0} Out{1}", imageIndex, FileFormatUtil.imageTypeToExtension(shape.getImageData().getImageType())); shape.getImageData().save(getMyDir() + imageFileName); imageIndex++; } } }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網