本文展示如何使用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().setUrl("C:\\Users\\Administrator\\Desktop\\dinosaur.png");
        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);
    }
}
 



 
					



