翻譯|使用教程|編輯:李顯亮|2021-03-31 10:23:27.927|閱讀 335 次
概述:本文介紹如何使用Spire.Presentation for Java將特定幻燈片中的形狀導(dǎo)出為圖像。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Spire.Presentation for Java 專業(yè)的 PowerPoint API,它允許開發(fā)人員在 Java 應(yīng)用程序中創(chuàng)建、讀取、寫入、轉(zhuǎn)換和保存 PowerPoint 文檔,而無需安裝 Microsoft PowerPoint。
本文介紹如何使用Spire.Presentation for Java將特定幻燈片中的形狀導(dǎo)出為圖像。可點(diǎn)擊此處下載最新版測試。
下面是示例PowerPoint文檔的屏幕截圖。
 
 
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
public class SaveShapeAsImage {
    public static void main(String[] args) throws Exception {
        //Create a Presentation object
        Presentation presentation = new Presentation();
        //Load the sample PowerPoint file
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\chart and table.pptx");
        //Get the first slide
        ISlide slide = presentation.getSlides().get(0);
        //Declare a BufferedImage variable
        BufferedImage image;
        //Loop through the shapes in the slide
        for (int i = 0; i < slide.getShapes().getCount(); i++) { //Save the specific shape as image data image = slide.getShapes().saveAsImage(i); //Write data to png file File file = new File(String.format("ToImage-%d.png", i)); ImageIO.write(image, "PNG", file); } } }
輸出結(jié)果
 
 
	 
	
	 
	
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn