本文展示如何使用spire.presentation for java为ppt中的图形添加阴影效果。除了文中展示的预设阴影效果,还可以添加内部阴影(innershadoweffect)、外部阴影(outershadoweffect)、柔化边缘阴影(softedgeeffect)等。
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, 240, 150);
iautoshape shape = slide.getshapes().appendshape(shapetype.rectangle,rect);
//将图片填充到图形
shape.getfill().setfilltype(fillformattype.picture);
shape.getfill().getpicturefill().getpicture().set;
shape.getfill().getpicturefill().setfilltype(picturefilltype.stretch);
shape.getline().setfilltype(fillformattype.none);
//设置阴影效果
presetshadow presetshadow = new presetshadow();
presetshadow.setpreset(presetshadowvalue.back_left_perspective);
presetshadow.getcolorformat().setcolor(color.lightgray);
//将阴影效果应用到图形
shape.geteffectdag().setpresetshadoweffect(presetshadow);
//保存文档
ppt.savetofile("output/shapeshadow.pptx", fileformat.pptx_2013);
}
}