ppt设计中为了美化图片效果,有时需要为图片添加阴影。本文将介绍如何使用spire.presentation为ppt中的图片设置阴影效果。
c#
//创建presentation实例,获取第一张幻灯片
presentation ppt = new presentation();
islide slide = ppt.slides[0];
//获取图片地址及长宽
string imagepath = "image.png";
image image = image.fromfile(imagepath);
float width = (float)image.width/2;
float height = (float)image.height/2;
//将图片添加至指定位置
rectanglef rect = new rectanglef(50, 80, width, height);
iautoshape shape = slide.shapes.appendshape(shapetype.rectangle, rect);
shape.fill.filltype = fillformattype.picture;
shape.fill.picturefill.picture.url = imagepath;
shape.fill.picturefill.filltype = picturefilltype.stretch;
shape.line.filltype = fillformattype.none;
//在不同的位置再次添加图片
rect = new rectanglef(300, 80, width, height);
shape = slide.shapes.appendshape(shapetype.rectangle, rect);
shape.fill.filltype = fillformattype.picture;
shape.fill.picturefill.picture.url = imagepath;
shape.fill.picturefill.filltype = picturefilltype.stretch;
shape.line.filltype = fillformattype.none;
//通过innershadoweffect对象创建阴影效果
innershadoweffect innershadow = new innershadoweffect();
innershadow.blurradius = 20;
innershadow.direction = 0;
innershadow.distance = 3;
innershadow.colorformat.color = color.black;
//在第二张图片上应用阴影效果
shape.effectdag.innershadoweffect = innershadow;
//保存文档
ppt.savetofile("imageshadow.pptx", fileformat.pptx2010);
vb.net
'创建presentation实例,获取第一张幻灯片
dim ppt as new presentation()
dim slide as islide = ppt.slides(0)
'获取图片地址及长宽
dim imagepath as string = "image.png"
dim image__1 as image = image.fromfile(imagepath)
dim width as single = csng(image__1.width) / 2
dim height as single = csng(image__1.height) / 2
'将图片添加至指定位置
dim rect as new rectanglef(50, 80, width, height)
dim shape as iautoshape = slide.shapes.appendshape(shapetype.rectangle, rect)
shape.fill.filltype = fillformattype.picture
shape.fill.picturefill.picture.url = imagepath
shape.fill.picturefill.filltype = picturefilltype.stretch
shape.line.filltype = fillformattype.none
'在不同的位置再次添加图片
rect = new rectanglef(300, 80, width, height)
shape = slide.shapes.appendshape(shapetype.rectangle, rect)
shape.fill.filltype = fillformattype.picture
shape.fill.picturefill.picture.url = imagepath
shape.fill.picturefill.filltype = picturefilltype.stretch
shape.line.filltype = fillformattype.none
'通过innershadoweffect对象创建阴影效果
dim innershadow as new innershadoweffect()
innershadow.blurradius = 20
innershadow.direction = 0
innershadow.distance = 3
innershadow.colorformat.color = color.black
'在第二张图片上应用阴影效果
shape.effectdag.innershadoweffect = innershadow
'保存文档
ppt.savetofile("imageshadow.pptx", fileformat.pptx2010)