Java 为 PPT 中的图形添加阴影效果
程序员文章站
2022-03-25 15:00:55
...
在PowerPoint文档中,给图片添加阴影效果能增强图片的逼真度,使其贴近现实效果,提升文档的美观度。 本文将展示如何使用Free Spire.Presentation for Java为PPT中的图形添加阴影效果。除了文中展示的预设阴影效果,还可以添加内部阴影(InnerShadowEffect)、外部阴影(OuterShadowEffect)、柔化边缘阴影(SoftEdgeEffect)等。
JAR包导入
方法一:下载Free Spire.Presentation for Java包并解压缩,然后将lib文件夹下的jar包作为依赖项直接导入到Java应用程序中。
方法二:通过Maven仓库安装jar包,配置pom.xml文件的代码如下:
<repositories> <repository> <id>com.e-iceblue</id> <url>http://repo.e-iceblue.cn/repository/maven-public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.presentation.free</artifactId> <version>2.6.1</version> </dependency> </dependencies>
import com.spire.presentation.*; import com.spire.presentation.drawing.FillFormatType; import com.spire.presentation.drawing.PictureFillType; import com.spire.presentation.drawing.PresetShadow; import java.awt.geom.Rectangle2D; import java.awt.Color; public class ShapeShadowEffect { public static void main(String[] args) throws Exception { //创建Presentation对象 Presentation ppt = new Presentation(); //获取第一页幻灯片 ISlide slide = ppt.getSlides().get(0); //添加一个图形 Rectangle2D rect = new Rectangle2D.Float(120, 80, 180, 150); IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE,rect); //将图片填充到图形 shape.getFill().setFillType(FillFormatType.PICTURE); shape.getFill().getPictureFill().getPicture().setUrl("C:\\Users\\Administrator\\Desktop\\cow.png"); shape.getFill().getPictureFill().setFillType(PictureFillType.STRETCH); shape.getLine().setFillType(FillFormatType.NONE); //设置阴影效果 PresetShadow presetShadow = new PresetShadow(); presetShadow.setPreset(PresetShadowValue.BACK_RIGHT_PERSPECTIVE); presetShadow.getColorFormat().setColor(Color.lightGray); //将阴影效果应用到图形 shape.getEffectDag().setPresetShadowEffect(presetShadow); //保存文档 ppt.saveToFile("ShapeShadow.pptx", FileFormat.PPTX_2013); } }
推荐阅读
-
PPT中利用自选图形轻松制作精美并可编辑的水晶球效果
-
在PPT2010中利用图形的图片填充功能实现类似2013版的抠图效果
-
PPT2010中为插入的图片配上精美的边框强化图片的视觉效果
-
WPS的ppt演示中如何插入相关的动画效果以进入效果为例
-
PPT中制作文本圆形效果让你的PPT与众不同以2007版为例
-
PPT2003中为自选图形设置渐变图片等填充效果美化你的PPT
-
在PPT中为标题或强调文字添加花边效果使文字更加充实和精致
-
Word2007中插入的图片怎么添加边框阴影等修饰效果
-
PPT2010中为插入的图片配上精美的边框强化图片的视觉效果
-
PPT中利用自选图形轻松制作精美并可编辑的水晶球效果