1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Spire.Presentation使用教程:在Java中设置PowerPoint图像的透明度

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

时间:2020-07-29 09:00:09

相关推荐

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

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

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

在 PowerPoint 中设置图像的透明度

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

以下是在 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 instancePresentation presentation = new Presentation();//Load a PowerPoint sample documentpresentation.loadFromFile("C:\Users\Test1\Desktop\sample.pptx");//Insert a shape to the specified position of the first slideRectangle2D.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 imageshape.getLine().setFillType(FillFormatType.NONE);//Sets the fill format typeshape.getFill().setFillType(FillFormatType.PICTURE);//Sets the type of fillingshape.getFill().getPictureFill().getPicture().setUrl("C:\Users\Test1\Desktop\Picture.png");//Sets the linked image's URLshape.getFill().getPictureFill().setFillType(PictureFillType.STRETCH);//Sets the picture fill mode//Set transparency of the imageshape.getFill().getPictureFill().getPicture().setTransparency(50);//Save the document to filepresentation.saveToFile("output/SetImageTransparency_result.pptx", FileFormat.PPTX_);}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。