Set aspect ratio for the picture in Excel

Hello aspose team,

We are going to insert the png image into the excel. When I try to insert the image with some height and width (whose aspect ratio is fine) into excel by changing its height and width using setHeight() and
setWidth() then the aspect ratio of image is not preserved.

Code snippet is:-

(for example :- I have an image with size 600*400 in dimension (whose aspect ratio is fine) when I try to insert the image using following code snippet the aspect ratio gets distorted)

int pictureIndex = ws.getPictures().add(0, 0, “600/400image.png”)
Picture picture = ws.getPictures().get(pictureIndex)
picture.setHeight(95)
picture.setWidth(170)

Is there any way to preserve the aspect ratio irrespective with its size in excel.

@niteshregmi1234,

Thanks for the sample code segment and details.

We will evaluate your issue and get back to you soon.

@niteshregmi1234,
We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSJAVA-43051 – Aspect ratio not maintained for the picture

@niteshregmi1234,
Please set Picture.RelativeToOriginalPictureSize as false with the latest fix.

picture.setRelativeToOriginalPictureSize(false);

aspose-cells-19.11.1.zip (6.6 MB)

Let us know your feedback.

@niteshregmi1234,

Please try our latest version/fix: Aspose.Cells for Java v19.11.2:

aspose-cells-19.11.2.zip (6.6 MB)

Please try the following sample code with the latest fix/version v19.11.2:
e.g
Sample code:

Workbook wb = new Workbook();
Worksheet ws = wb.getWorksheets().get(0);
int pictureIndex = ws.getPictures().add(0, 0, "600x400.png");
Picture picture = ws.getPictures().get(pictureIndex);
picture.setHeight(500);
picture.setWidth(170);
picture.setLockAspectRatio(true);
picture.setRelativeToOriginalPictureSize( false);
System.out.println(picture.isLockAspectRatio());
wb.save("600x400_TRUE.xlsx");

Thanks, @Amjad_Sahi we will verify from our end.
Thanks for the fix.

@niteshregmi1234,

Please take your time to evaluate the fix/version. Hopefully the fixed version will pass your test cases.

The issues you have found earlier (filed as CELLSJAVA-43051) have been fixed in Aspose.Cells for Java v19.12. This message was posted using Bugs notification tool by ahsaniqbalsidiqui