java知识点ppt背景图片_Java 给PPT幻灯片添加背景颜色和背景图片

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

Jar文件获取及导入:

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

66fbd18770b7c835e6f8def0ba41cfc0.png

方法2:通过maven仓库安装导入。具体安装教程详见此网页。

【示例1】添加背景图片

import com.spire.presentation.*;

import com.spire.presentation.drawing.*;

public class BackgroundImage {

public static void main(String[] args) throws Exception {

String inputFile = "C:\\Users\\Test1\\Desktop\\Sample.pptx";

String imageFile = "C:\\Users\\Test1\\Desktop\\Image.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();

}

}

背景图片添加效果:

2c98dfa7dc8b82b8dd25146455298275.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:\\Users\\Test1\\Desktop\\Sample.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();

}

}

纯色背景颜色添加效果:

5b476a17e2618a168a7abd880dac7819.png

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

import com.spire.presentation.*;

import com.spire.presentation.drawing.*;

import java.awt.*;

public class GradientColor {

public static void main(String[] args) throws Exception {

String inputFile = "C:\\Users\\Test1\\Desktop\\Sample.pptx";

String outputFile = "output/setGradientColor.pptx";

Presentation ppt = new Presentation();

ppt.loadFromFile(inputFile);

ppt.getSlides().get(0).getSlideBackground().setType(BackgroundType.CUSTOM);

//设置文档的背景填充模式为渐变色填充,设置颜色

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.darkGray);

ppt.saveToFile(outputFile, FileFormat.PPTX\_2010);

ppt.dispose();

}

}

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

827afa00315a8067725813e9541e362b.png

(本文完)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值