Duplicate Pictures causes repeat of first picture

Hi,

I have a situation where I may want to add the same picture multiple times to a slides document. In my example I have two images 'img1' and 'img2'. I create 4 pictures and add them one at a time in the order 'img1', 'img2', 'img1' and 'img2'. However in my output I get 'img1', 'img2', 'img1' and 'img1'. I noticed when adding the pictures to the Presentation, it does not add duplicate pictures. However, when I try to find the picture Id, if it was the 3rd or 4th picture added, it returns 'img1' which was the first image added.

Stepping through code it appears that the picture assumes it is the first in the list unless a new picture is added, then the id is updated. Is this the expected behaviour or should the same picture be allowed to be added multiple times?

If this is the expected behaviour, is there any way I can interate through Presentation.Pictures and see if the picture I am trying to add is already in use so I can get the Picture.PictureId of the picture?

I have included my source code.

Thanks

Presentation presentation = new Presentation();

Slide slide = presentation.Slides[0];

string img1 = "img1.bmp";

string img2 = "img2.bmp";

Picture picture = new Picture(presentation, img1);

presentation.Pictures.Add(picture);

slide.Shapes.AddPictureFrame(picture.PictureId, 100, 100, 500, 500);

picture = new Picture(presentation, img2);

presentation.Pictures.Add(picture);

slide.Shapes.AddPictureFrame(picture.PictureId, 100, 650, 500, 500);

picture = new Picture(presentation, img1);

presentation.Pictures.Add(picture);

slide.Shapes.AddPictureFrame(picture.PictureId, 100, 1200, 500, 500);

picture = new Picture(presentation, img2);

presentation.Pictures.Add(picture);

slide.Shapes.AddPictureFrame(picture.PictureId, 100, 1750, 500, 500);

presentation.Write("test.ppt");

Hi,

You don’t need to add both pictures again. Just note down their ids which are returned by presentation.Pictures.Add(picture); and then use that id in Shapes.AddPictureFrame() every time when you need to insert it again.

Thanks for the reply. I may not have explained myself properly, so I’ll have another attempt.

When I try to add an image which happens to have the same image data as a previously-added image – even though it is a different filename and different object – Aspose.Slides silently fails to add the image object.

My guess is that you must be doing a full byte-by-byte match of each image being added with previously added ones, as that’s the only way I can understand what is happening.

When I try to add the new image object that happens to have the same image data as an earlier one, Slides appears to do nothing at all. The PictureId remains at the initial default of 1. Nothing else changes. It ignores my request.

It would be appreciated if Aspose.Slides:
• Either stop matching up images with previously added ones, or
• Better still, update the PictureId of the new object to the correct value so that I can identify the correct entry in Presentation.Pictures

It looks like you simply don’t understand how it works.
Presentation.Pictures is common storage of images for the whole presentation.
Each added image has unique Id which can be used in any place in a presentation.
For example to fill a background or as a main image in a PictureFrame.
One image Id can be used in several objects.
If you add image and Id equal to 1 that mean you can use this Id in ALL PictureFrames
with identical images. It doesn’t matter what file name image has.