Spire.Presentation使用教程:在Java中设置PowerPoint图像的透明度

Spire.Presentation for Java专业的 PowerPoint API,它允许开发人员在 Java 应用程序中创建、读取、写入、转换和保存 PowerPoint 文档,而无需安装 Microsoft PowerPoint。如有需要,可以进入慧都下载最新版!

当图片出现在文字上时,文字会被图片覆盖而无法显示。此时,您可以设置图片的透明度,以便在图片上方显示文字。本文将演示如何使用Spire.Presentation for Java将图像插入到 PowerPoint 中的特定幻灯片位置并设置其透明度。

在 PowerPoint 中设置图像的透明度

本代码示例中涉及到了大量的类和方法,为了方便大家了解,特提供下表。

姓名描述
IAutoShape 界面代表一个形状。
形状列表类表示形状的集合。
图片填充格式类表示图片填充样式。
ShapeList.appendShape(ShapeType.shapeType, Rectangle2D.Double) 方法将新形状添加到列表中。
IAutoShape.getLine().setFillType(FillFormatType.value) 方法设置线条的填充格式类型。
IAutoShape.getFill().setFillType(FillFormatType.value) 方法设置形状的填充格式类型。
IAutoShape.getFill().getPictureFill() 方法获取图片填充格式。
PictureFillFormat.setFillType(PictureFillType.value) 方法设置图片填充模式。
PictureFillFormat.getPicture().setUrl(java.lang.String value) 方法为图片填充设置图像的 URL。
PictureFillFormat.getPicture().setTransparency() 方法设置图片填充的透明度。

以下是在 PowerPoint 中设置图像透明度的一些步骤:

  • 创建一个Presentation实例并使用Presentation.loadFromFile()方法加载一个 PowerPoint 示例文档。
  • 使用Presentation.getSlides().get()方法获取指定的幻灯片,并使用ShapeList.appendShape(ShapeType.shapeType, Rectangle2D.Double)方法将形状插入到幻灯片的指定位置。
  • 使用图像填充形状并使用IAutoShape.getFill().setFillType(FillFormatType.value)方法设置填充格式类型。
  • 使用IAutoShape.getFill().getPictureFill()方法获取图片填充格式。
  • 设定用图像填充模式PictureFillFormat.setFillType(PictureFillType.value)方法中,设置使用该图像的URL PictureFillFormat.getPicture()。setUrl(java.lang.String中值)的方法,并设置使用该图像的透明度PictureFillFormat.getPicture( ).setTransparency()方法。
  • 使用Presentation.saveToFile()方法保存文档。
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import java.awt.geom.Rectangle2D;

public class SetImageTransparency {
    public static void main(String[] args) throws Exception {
        //Create a Presentation instance
        Presentation presentation = new Presentation();

        //Load a PowerPoint sample document
        presentation.loadFromFile("C:\Users\Test1\Desktop\sample.pptx");

        //Insert a shape to the specified position of the first slide
        Rectangle2D.Double rect1 = new   Rectangle2D.Double(50, 130, 275, 150);
        IAutoShape shape =  presentation.getSlides().get(1).getShapes().appendShape(ShapeType.RECTANGLE, rect1);

        //Fill the shape with an image
        shape.getLine().setFillType(FillFormatType.NONE);//Sets the fill format type
        shape.getFill().setFillType(FillFormatType.PICTURE);//Sets the type of filling
        shape.getFill().getPictureFill().getPicture().setUrl("C:\Users\Test1\Desktop\Picture.png");//Sets the linked image's URL
        shape.getFill().getPictureFill().setFillType(PictureFillType.STRETCH);//Sets the picture fill mode

        //Set transparency of the image
        shape.getFill().getPictureFill().getPicture().setTransparency(50);

        //Save the document to file
        presentation.saveToFile("output/SetImageTransparency_result.pptx", FileFormat.PPTX_2010);
    }
}

国产PPT格式控件Spire.Presentation功能演示:在Java中设置PowerPoint图像的透明度

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值