翻譯|使用教程|編輯:張瑩心|2021-11-09 10:16:59.300|閱讀 276 次
概述:當圖片出現在文字上時,文字會被圖片覆蓋而無法顯示。此時,您可以設置圖片的透明度,以便在圖片上方顯示文字。本文將演示如何使用Spire.Presentation for Java將圖像插入到 PowerPoint 中的特定幻燈片位置并設置其透明度。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
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 中設置圖像透明度的一些步驟:
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感興趣,可以了解具體授權價格和使用機制。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn