Spire.Presentation for Java 专业的 PowerPoint API,它允许开发人员在 Java 应用程序中创建、读取、写入、转换和保存 PowerPoint 文档,而无需安装 Microsoft 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); }}
是E-iceblue官方友好合作伙伴,如果您对spire.Presentation感兴趣,可以联系在线客服了解具体授权价格和使用机制。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!