PPT幻燈片生成時(shí),系統(tǒng)默認(rèn)是無(wú)色背景填充,幻燈片設(shè)計(jì)需要手動(dòng)設(shè)置背景效果,可設(shè)置顏色填充或者圖片背景填充。本文將對(duì)此介紹具體實(shí)現(xiàn)方法。
Jar文件導(dǎo)入方法(參考):
步驟1:在Java程序中可新建一個(gè)文件夾命名為L(zhǎng)ib,并將下載包中的jar文件復(fù)制到新建的文件夾下。
步驟2:復(fù)制文件后,添加到引用類(lèi)庫(kù):選中這個(gè)jar文件,點(diǎn)擊鼠標(biāo)右鍵,選擇“Build Path” – “Add to Build Path”。完成引用。
Java示例1:設(shè)置背景顏色
1.純色背景
import com.spire.presentation.*;import com.spire.presentation.drawing.*;public class BackgroundColor { public static void main(String[] args) throws Exception { String inputFile = "sample.pptx"; String outputFile = "output/setBackgroundColor.pptx"; Presentation ppt = new Presentation(); ppt.loadFromFile(inputFile); ppt.getSlides().get(0).getSlideBackground().setType(BackgroundType.CUSTOM); //設(shè)置文檔的背景填充模式為純色填充,設(shè)置顏色 ppt.getSlides().get(0).getSlideBackground().getFill().setFillType(FillFormatType.SOLID); ppt.getSlides().get(0).getSlideBackground().getFill().getSolidColor().setColor(java.awt.Color.PINK); ppt.saveToFile(outputFile, FileFormat.PPTX_2010); ppt.dispose(); }}
純色背景效果:
2.漸變背景
import java.awt.Color;import com.spire.presentation.*;import com.spire.presentation.drawing.*;public class BackgroundColor { public static void main(String[] args) throws Exception { String inputFile = "test.pptx"; String outputFile = "output/setBackgroundColor2.pptx"; Presentation ppt = new Presentation(); ppt.loadFromFile(inputFile); ppt.getSlides().get(0).getSlideBackground().setType(BackgroundType.CUSTOM); //設(shè)置文檔的背景填充模式為漸變填充,并設(shè)置顏色 ppt.getSlides().get(0).getSlideBackground().getFill().setFillType(FillFormatType.GRADIENT); ppt.getSlides().get(0).getSlideBackground().getFill().getGradient().getGradientStops().append(0, Color.white); ppt.getSlides().get(0).getSlideBackground().getFill().getGradient().getGradientStops().append(1,Color.green); ppt.saveToFile(outputFile, FileFormat.PPTX_2010); ppt.dispose(); }}
漸變色背景效果:
Java示例2:圖片背景
import com.spire.presentation.*;import com.spire.presentation.drawing.*;public class ImageBackground { public static void main(String[] args) throws Exception { String inputFile = "Input.pptx"; String imageFile = "1.png"; String outputFile = "output/ImgBackgroundColor.pptx"; Presentation ppt = new Presentation(); ppt.loadFromFile(inputFile); ppt.getSlides().get(0).getSlideBackground().setType(BackgroundType.CUSTOM); //設(shè)置文檔的背景填充模式為圖片填充 ppt.getSlides().get(0).getSlideBackground().getFill().setFillType(FillFormatType.PICTURE); ppt.getSlides().get(0).getSlideBackground().getFill().getPictureFill().setAlignment(RectangleAlignment.NONE); ppt.getSlides().get(0).getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH); ppt.getSlides().get(0).getSlideBackground().getFill().getPictureFill().getPicture().setUrl((new java.io.File(imageFile)).getAbsolutePath()); ppt.saveToFile(outputFile, FileFormat.PPTX_2010); ppt.dispose(); }}
圖片背景效果:
![]() |
以上所述是小編給大家介紹的Java設(shè)置PPT幻燈片背景——純色、漸變、圖片背景詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)VeVb武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選