Picture.PictureId not unique!

Hi all,

Pb :
When adding pictures to my presentation, it seems that the PictureId auto-generated by the api is always the same, so not ‘Unique’ as stated in the documentation.

Presentation pres = new Presentation(path);

Picture pic = new Picture(pres,“1.jpg”);
Picture pic2 = new Picture(pres,“2.jpg”);
Picture pic3 = new Picture(pres,“3.jpg”);

pres.Pictures.Add(pic);
pres.Pictures.Add(pic2);
pres.Pictures.Add(pic3);

// Launching DEBUG …


My source Powerpoint file has already 2 Pictures in it (with PictureIds 2 & 3) …
The 3 newly added pics have all the same PictureId (2), which correspond to one existing Picture.

Am I doing something wrong ??

Thanks a lot

Stephane






Dear Stephane,

Different pictures have unique id.
Two pictures with identical size, format, crc32 (and some additional info) considered to be equal and have the same id.

Thank you for your prompt reply Alexey, but my pictures all have different sizes …

so they normally shouldn’t have the same Id



Stephane

Dear Stephane,

Did you create source presentation in MS PowerPoint?
In any case, could you send this ppt and 3 images to my email please?
I would like to check it by myself because it’s very strange.

Thanks !

I have sent you the files per mail
Yes I have created the presentation with powerpoint

Regards

Stephane

Dear Stephane,

You checked PictureId too early.

Picture pic = new Picture(pres,“1.jpg”);
Picture’s constructor doesn’t really add picture to the ppt. It just create it in the memory and PictureId is undefined on this stage.

pres.Pictures.Add(pic);
After you add picture to the real ppt’s Pictures collection it can calculate own Id and PictureId = 4 now.

I check the values after having added the picture …

pres.Pictures.Add(pic);

// and then --> DEBUG



so the problem is still there …

Stephane

Dear Stephane,

Watch window after executing 5 pres.Pictures.Add lines with your ppt and images:

pic.PictureId 0x4 int
pic4.PictureId 0x5 int
pic5.PictureId 0x6 int
pic6.PictureId 0x7 int
pic7.PictureId 0x8 int

All pictures have unique ids.

it’s really weird but when I do exactly what u say I still have all pics with same PictureId : 3

I hope you use 1.6.4 hot fix?

yes I do …


Stephane

Oops sorry I had a bad reference in my project and I wasn't pointing at the hotfix.

Now it works with hotfix 1.6.4.

Thanks for your time Alexey !

Stephane

I have a new problem …

when I do this on a presentation with many existing pictures in it :

Picture picTemp = new Picture(pres,@“C:\pics\1.jpg”);
pres.Pictures.Add(picTemp);

// --> picTemp gets the ID : 13

// and then later …
Picture picTemp2 = new Picture(pres,@“C:\pics\1.jpg”);
pres.Pictures.Add(picTemp2);

// --> picTemp2 gets the ID 1 … why not 13 ??

// Note : picture with ID1 is far from being C:\pics\1.jpg (different sizes, formats … )

Thanks in advance

Stephane

Dear Stephane,

I need real files to tell exactly why it happened.

files sent per mail

thanks

Stephane

Dear Stephane,

Pictures.Add method returns correct id 13 in both cases.
The second picture was not added to the presentation and it has wrong id of course.

I’d suggest to to use next way to add pictures:

Picture pic = pres.GetPictureById(pres.Pictures.Add(new Picture(pres, “1.jpg”)));
Picture pic2 = pres.GetPictureById(pres.Pictures.Add(new Picture(pres, “1.jpg”)));

In this case pic and pic2 will have reference to the same Picture with id 13.

‘Presentation’ class doesn’t have a method ‘GetPictureById’ …

Dear Stephane,

I’m sorry, it’s in Pictures class.
pres.Pictures.GetPictureById

Any news on that? I get ID 13 too very often. And I get a red X in my picture frame

Hi,



All such problems usually because of wrong code.

Could you send me real ppt file before inserting image and with red cross

and also your code.