Change in Behavior when Aspect Ratio Lock Is Set for PictureFrame in Java

Hello.
We are observing change in behavior when inserting an image into PictureFrame after setting aspect ratio lock to “true”.
The scenario is as following:

  1. Create a new Powerpoint presentation;

  2. Add a new image to the last slide:
    final IPPImage imgx = pptx.getImages().addImage(imagebytes);
    int imageWidth = imgx.getWidth();
    int imageHeight = imgx.getHeight();

    ISlide islide = presentation.getSlides().get_Item(slides.size()-1);
    IPictureFrame pf = islide.getShapes().addPictureFrame(ShapeType.Rectangle, 10, 20, newWidth,
    imageHeight * (newWidth/imageWidth), imgx);

  3. Set aspect ratio locked : pf.getPictureFrameLock().setAspectRatioLocked(true);

  4. Change image dimensions (width and height)
    IPPImage newImg = pptx.getImages().addImage(imagebytes2);

  5. Set the new image on the shape; and change shape width
    // set the new image
    ((IPictureFrame)shape).getPictureFormat().getPicture().setImage(newImg);
    shape.setWidth((float)newImg.getWidth() / (float)newImg.getHeight() * shape.getHeight());

Previously, the published powerpoint document had the same scale height and scale width after image update (see attached screenshot ImageUpdate_BeforeEvaluateAspose23_03.png)
Now with the version of Aspose.Slides 23.03 the scale height and width are different and as a result the inserted image seems ‘squashed’ (see attached screenshot ImageUpdateInShape_changeInAspose23_03.png).
Please let us know if this is a known issue, or there is some setting that needs to be applied in order to have the same scale height and width.
Thank you.
ImageUpdate_BeforeEvaluateAspose23_03.png (74.6 KB)
ImageUpdateInShape_Aspose23_03.png (57.4 KB)

@oraspose,
Thank you for contacting support.

Unfortunately, I was unable to reproduce the problem you described. Please share the following:

  • image files you used
  • complete code example
  • your output presentation file

Hi Andrey.
Attached is the zip containing the following:

  • Presentation.pptx - empty input pptx document
  • image1_add_96x110px.emf - initial image added to the slide;
  • image2_update_192x58px.emf - image with changed dimensions updated in the same slide (twice increased width and smaller height);
  • Presentation_Test1_newImage.pptx - output of save to PPT after adding first image;
  • Presentation_Test2_changedImage.pptx - output of save to PPT after updating image in the slide;
  • InsertImageIntoShapeChangedAspectRatio.java - source of the code example.

Please let me know if you need anything else.
insertImageChangeInBehavior.zip (109.4 KB)
Note that we currently using the older version of Aspose.Slides and would like to find a workaround to account to this change in behavior when image with different dimensions is updated in the slide.
Thank you in advance,
Yan

@oraspose,
Thank you for the additional information. I will check the problem you described and get back to you as soon as possible.

@oraspose,
I reproduced the problem you described.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESJAVA-39193

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thanks, Andrey.
I have opened a paid support ticket #176796 Containerize.IdentityServer - Single sign-on to access all applications and services of Aspose Pty Ltd.
and will be waiting for the resolution.

Regards,
Yan

@oraspose,
Our developers have investigated the case.

Please note that the IPictureFrameLock.setAspectRatioLocked method preserves the aspect ratio of the shape, not the image it contains. And setting the new image doesn’t change the parent PictureFrame size.

So, your code:

  1. locks the aspect ratio of the PictureFrame that is the same size as the first image;
  2. changes the PictureFrame Width, which caused the Height to change (AspectRatioLocked property in action).

If you want to change the PictureFrame Width only, then you can:

  1. directly change the shape frame:
//===== update the image and set the new image on the shape
IShape shape = islide.getShapes().get_Item(0);
final IPPImage newImg = pptx.getImages().addImage(imagebytes2);

// set the new image
((IPictureFrame) shape).getPictureFormat().getPicture().setImage(newImg);
float newWidth = (float)newImg.getWidth() / (float)newImg.getHeight() * shape.getHeight();
IShapeFrame frame = shape.getFrame();
shape.setFrame(new ShapeFrame(frame.getX(), frame.getY(), newWidth, frame.getHeight(), frame.getFlipH(), frame.getFlipV(), frame.getRotation()));

pptx.save(folderPath + "output2_changedImage.pptx", SaveFormat.Pptx, options);
  1. temporarily disable the aspect ratio lock, before making the size changes:
//===== update the image and set the new image on the shape
IShape shape = islide.getShapes().get_Item(0);
IPPImage newImg = pptx.getImages().addImage(imagebytes2);

// set the new image
IPictureFrame picFrame = (IPictureFrame)shape;
picFrame.getPictureFormat().getPicture().setImage(newImg);

// disable the aspect ratio lock
picFrame.getPictureFrameLock().setAspectRatioLocked(false);

// set the new width
shape.setWidth(((float)newImg.getWidth() / (float)newImg.getHeight() * shape.getHeight()));

// enable the aspect ratio lock
picFrame.getPictureFrameLock().setAspectRatioLocked(true);

pptx.save(folderPath + "output2_changedImage.pptx", SaveFormat.Pptx, options);

Hi Andrey,
Thank you for the investigation and for providing the resolution.
The issue is now resolved.
Regards,
Yan

@oraspose,
We are glad to know that the issue has been resolved on your end. Thank you for using Aspose.Slides.