我需要在演示文稿中插入一张新幻灯片并将图像设置为背景。我找到了method to insert a new slide into a presentation,并且有效。
基于this method,我试图将图像插入幻灯片并设置为背景,但是失败了。
这是我不完整的代码。
// Declare and instantiate a new slide.
Slide slide = new Slide(new CommonSlideData(new Background()));
// Specify background properties
BackgroundProperties bgPr = new BackgroundProperties();
BlipFill blipFill = new BlipFill() { Dpi = 0, RotateWithShape = true };
string embedId = "rId2"; // specify embed id
Drawing.Blip blip = new Drawing.Blip(new Drawing.Luminance()) { Embed = embedId };
Drawing.SourceRectangle srcRect = new Drawing.SourceRectangle();
Drawing.Stretch stretch = new Drawing.Stretch(new Drawing.FillRectangle());
blipFill.AppendChild(blip);
blipFill.AppendChild(srcRect);
blipFill.AppendChild(stretch);
Drawing.EffectList effectList = new Drawing.EffectList();
bgPr.AppendChild(blipFill);
bgPr.AppendChild(effectList);
slide.CommonSlideData.Background.AppendChild(bgPr);
// Create the slide part for the new slide.
SlidePart slidePart = presentationPart.AddNewPart<SlidePart>();
// Add imagePart to slidePart
ImagePart imagePart = slidePart.AddImagePart(ImagePartType.Bmp, embedId);
using (FileStream fileStream = new FileStream(imagePath, FileMode.Open))
{
imagePart.FeedData(fileStream);
}
// Save the new slide part.
slide.Save(slidePart);