apache poi powerpoint图像

本文概述

  • Apache POI侧面图片示例
要在Powerpoint幻灯片中设置图像,我们可以使用POI API的addPicture()和createPicture()方法。在下面的示例中,我们使用了两种方法在文档中写入图像。
Apache POI侧面图片示例
package poiexample; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import org.apache.poi.util.IOUtils; import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xslf.usermodel.XSLFPictureData; import org.apache.poi.xslf.usermodel.XSLFPictureShape; import org.apache.poi.xslf.usermodel.XSLFSlide; public class ReOrderSlidesExample { public static void main(String[] args) throws FileNotFoundException, IOException { XMLSlideShow ppt = new XMLSlideShow(); try (OutputStream os = new FileOutputStream("srcmini.pptx")) { XSLFSlide slide = ppt.createSlide(); byte[] pictureData = http://www.srcmini.com/IOUtils.toByteArray(new FileInputStream("jtp.png")); XSLFPictureData pd = ppt.addPicture(pictureData, XSLFPictureData.PictureType.PNG); XSLFPictureShape pic = slide.createPicture(pd); ppt.write(os); }catch(Exception e) { System.out.println(e); } } }

【apache poi powerpoint图像】输出:
apache poi powerpoint图像

文章图片

    推荐阅读