I am having a problem where my images are not showing up when I try to set an existing PictureFrame.PictureId to a new picture that I added to the presentation. If I add a new PictureFrame for the new picture then the image shows up so I know the image is getting into the presentation, but I cannot seem to get an existing PictureFrame to display it.
I wrote a small WindowsApplication to test with that just has one real method where I use a bool to test the 2 different approaches mentioned above.
114 private void test(bool setId)
115 {
116 string newFile = "NewDemo.ppt";
117 string file = "demo.ppt";
118 string imgFile = "palmOneLogo.jpg";
119
120 if (File.Exists(file) && File.Exists(imgFile))
121 {
122 //
123 // New licensing scheme
124 //
125 //License license = new License();
126 //license.SetLicense("Aspose.PowerPoint.lic");
127
128 Presentation pres = new Presentation(file);
129
130 Slide slide = pres.GetSlideByPosition(1);
131
132 foreach (Shape shape in slide.Shapes)
133 {
134 if (shape is PictureFrame)
135 {
136 PictureFrame pf = shape as PictureFrame;
137
138 Debug.WriteLine("Picture Count: " + pres.Pictures.Count.ToString());
139 Aspose.PowerPoint.Picture pic = new Aspose.PowerPoint.Picture(pres, imgFile);
140 int picId = pres.Pictures.Add(pic);
141 Debug.WriteLine("Picture Count: " + pres.Pictures.Count.ToString());
142
143 if (setId)
144 {
145 //This does NOT work - i get an empty PictureFrame
146 pf.PictureId = picId;
147 }
148 else
149 {
150 //This does work - the new PictureFrame shows my added image
151 int pictureWidth = pic.Image.Width * 5;
152 int pictureHeight = pic.Image.Height * 5;
153 PictureFrame pf1 = slide.Shapes.AddPictureFrame(picId, 75, 75, pictureWidth, pictureHeight);
154 }
155 break;
156 }
157 }
158
159 pres.Write(newFile);
160 if (File.Exists(newFile))
161 Process.Start(newFile);
162 else
163 MessageBox.Show("No New File!");
164 }
165 else
166 MessageBox.Show("No Files!");
167 }