public static void AddDbImage()
{
Presentation pres = new Presentation();
Presentation Template = new Presentation("D:\\Aspose Data\\ImageTemp.ppt");
Slide slide = Template.GetSlideByPosition(1);
Slide SrcSlide=null ;
System.Collections.SortedList sList = null;
Shape shp=null ;
PictureFrame pf;
Picture pic;
int picId = 0;
int iComp=3;//total compnents
int ImginComp=0;
int sldImgCounter = 0;
for(; iComp > 0; iComp--)
{
ImginComp=5;//These are images in any components
for (int i = 0; i < ImginComp; i++)
{
if (i%3== 0 )//If new component or the component has more than three images
{
sList = new System.Collections.SortedList();
//Cloning the selected slide at the end of another presentation file
SrcSlide=Template.CloneSlide(slide, pres.Slides.LastSlidePosition + 1, pres, sList);
sldImgCounter = 1;
}
if (sldImgCounter == 1)
shp = Aspose.Slides.Util.SlideUtil.FindShape(SrcSlide, "Image1");//Image1 is alternative text of picture frame
else if (sldImgCounter == 2)
shp = Aspose.Slides.Util.SlideUtil.FindShape(SrcSlide, "Image2");
else if (sldImgCounter == 3)
shp = Aspose.Slides.Util.SlideUtil.FindShape(SrcSlide, "Image3");
if (shp is PictureFrame)
{
//Here we are adding the image and replacing the images in desired PictureFrame
pf = (PictureFrame)shp;
pic = new Picture(pres, "C:\\demo.jpg");//Add Your desired image here
//Adding the picture object to pictures collection of the presentation
//After the picture object is added, the picture is given a uniqe picture Id
picId = pres.Pictures.Add(pic);
pf.PictureId = picId;
sldImgCounter++;
}
}
//If there are less then three images in slide then the rest of
// temaplate picture frames in that particular slide are to be deleted
if (sldImgCounter < 4)
{
for (int iTemp = sldImgCounter; iTemp <= 4; iTemp++)
{
shp = Aspose.Slides.Util.SlideUtil.FindShape(SrcSlide, "Image" + iTemp );
SrcSlide.Shapes.Remove(shp);
}
}
}
//Removing default slide
pres.Slides.RemoveAt(0);
pres.Write("NewPres.ppt");
}