java获取屏幕颜色_Java 给PPT幻灯片添加背景颜色和背景图片

制作一个精美的PPT文档,不仅要求内容充实、排版得当;同时对于背景颜色的搭配,尤其是背景图片的设置也尤为重要。恰当的背景颜色或图片能够使PPT更加美观,引人注目。本文就将通过使用Java程序来演示如何给PPT幻灯片添加背景颜色和背景图片。背景颜色主要分为纯色背景颜色和渐变色背景颜色。

使用工具:Free Spire.Presentation for Java(免费版)

Jar文件获取及导入:

方法1:通过E-iceblue中文官网下载获取jar包。解压后将lib文件夹下的Spire.Presentation.jar文件导入Java程序。(如下图)

ac5aab1dbf1769fb55cfdefeffa7d9af.png

方法2:通过maven仓库安装导入。具体安装教程详见E-iceblue中文官网。

【示例1】添加背景图片

import com.spire.presentation.*;import com.spire.presentation.drawing.*;public class BackgroundImage {    public static void main(String[] args) throws Exception {        String inputFile = "C:甥敳獲Test1DesktopSample.pptx";        String imageFile = "C:甥敳獲Test1DesktopImage.jpg";        String outputFile = "output/setBackgroundImage.pptx";        Presentation ppt = new Presentation();        ppt.loadFromFile(inputFile);        ppt.getSlides().get(0).getSlideBackground().setType(BackgroundType.CUSTOM);      //设置文档的背景填充模式为图片填充        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();    }}

背景图片添加效果:

9d95d64bb6b24c7601570fe2493b1dca.png

【示例2】添加背景颜色

Part 1:添加纯色背景颜色

import com.spire.presentation.*;import com.spire.presentation.drawing.*;public class PureBackgroundColor {    public static void main(String[] args) throws Exception {        String inputFile = "C:甥敳獲Test1DesktopSample.pptx";        String outputFile = "output/PureBackgroundColor.pptx";        Presentation ppt = new Presentation();        ppt.loadFromFile(inputFile);        ppt.getSlides().get(0).getSlideBackground().setType(BackgroundType.CUSTOM);      //设置文档的背景填充模式为纯色填充,设置颜色        ppt.getSlides().get(0).getSlideBackground().getFill().setFillType(FillFormatType.SOLID);        ppt.getSlides().get(0).getSlideBackground().getFill().getSolidColor().setColor(java.awt.Color.LIGHT_GRAY);        ppt.saveToFile(outputFile, FileFormat.PPTX_2010);        ppt.dispose();    }}

纯色背景颜色添加效果:

4eb65649e19fe551b25f7fb8fbb8a171.png

Part 2:添加渐变色背景颜色

渐变色背景颜色添加效果:

4814a4f02d64f769b03b9e05b02c0c85.png

(本文完)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值