Aspose Slides: How to adjust the scale height and width value for IShape or IPictureFrame

Hi,

I'm using Aspose Slides v14.1.2.0 (which is awesome btw) to create PowerPoint presentations and came across a scenario where the added image is scaled to 133% Height and 133% Width when examining the PowerPoint slide and viewing the image's "Size and Position" properties.

The question: is there a way to adjust the scale height and scale width properties of the IPictureFrame or IAutoShape?

The sample code below to place the image onto the slide:

// Add the image to the presentation, where bitmap is some image of type Bitmap
IPPImage ppImage = presentation.Images.AddImage(bitmap);

// Add the image to the slide, where slide is ISlide
slide.Shapes.AddPictureFrame(ShapeType.Rectangle, leftPostion, topPosition, bitmap.Width, bitmap.Height, ppImage);

Any help would be greatly appreciated!

Stephen

Hi Stephen,

I have observed the requirements shared by you and regret to share that at present the support for setting relative image height is not working in Aspose.Slides for .NET 14.1.2 for Picture Frame at the moment. I have added an issue with ID SLIDESNET-35103 to further investigate the issue and provide requested support.

However, the same feature is presently avaiable in legacy Aspose.Slides for .NET 8.4.0 API and you may please use the following sample code to serve the purpose for the time being.


public static void TestRelativeHeight()
{
Presentation pres = new Presentation(“D:\Aspose Data\34419.pptx”);
PictureFrame pf = pres.Slides[0].Shapes[0] as PictureFrame;
pf.RelativeScaleHeight = 0.8f;
pf.RelativeScaleWidth = 1.35f;
pres.Write(“D:\Aspose Data\34419 out.pptx”);
}

Many Thanks,

Hi,

I am working with Stephen on the same project for the issue identified above. We would really love to continue to use Version 14 with the unified framework, but image scaling is giving us much troubles.

Essentially when adding a new image into the presentation it automatically seems to choose a random scale. All we want is to add a brand new PictureFrame with scale defaulting to 100%x100%. The fact that there is no way to make the PictureFrame stay at normal scale is almost making this version unusable for us.

Are you able to identify any workaround for us to use normally scaled PictureFrames? We do not require the ability to adjust the scaling, just need it to be standard scaling by default?

Any help is greatly appreciated.

Thanks,
Travis

Hi Travis,

I have verified the issue status from our issue tracking system and regret to share that the issue is still unresolved. However, I have raised the priority of the issue to High and have also requested our development team to kindly expedite the investigation. Unfortunately, at the moment there is no workaround that I may offer in this regard. All you can do is to set the bounds for PictureFrame and image gets accommodated inside that.

I will share the further feedback with you as soon as it will be shared by our development team in this regard.

Many Thanks,

The issues you have found earlier (filed as SLIDESNET-35103) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
(1)

same issue with java, I have tested Aspose.Slides for java version 16.12.0, but I still get 133%, can I conclude this issue is not resolved for java ?

Hi,


I have observed your comments. Can you please share source presentation and source data and generated presentation. We will investigate further to help you out.

Best Regards,

Presentation presentation = createPresentation(“EmptyPage.pptx”);

byte[] imageBytes = loadFileBytes(“testImage.jpg”);

ISlideCollection slides = presentation.getSlides();

IGlobalLayoutSlideCollection layoutSlides = presentation.getLayoutSlides();

ILayoutSlide layoutSlide = layoutSlides.get_Item(0);

ISlide islide = slides.addEmptySlide(layoutSlide);

IPPImage imgx = presentation.getImages().addImage(new ImageContent(imageBytes).getContent());

PictureFrame pf =

(PictureFrame)islide.getShapes().addPictureFrame(ShapeType.Rectangle, 10, 20, imgx.getWidth(), imgx.getHeight(), imgx);

pf.setRelativeScaleHeight(1.0f);

pf.setRelativeScaleWidth(1.0f);

presentation.save(new ByteArrayOutputStream(), SaveFormat.Pptx, new LoadOptions());

//////////////////////////////////////

the above is the code I created the issue. attached testImageScale.pptx is the result file. if you open it with PowerPoint at slide 2, right click the image -> Size and Position, you will see that the Scale height and Scale width are set at 96%



actually we did many tests, as long as the image is horizontally wide, it will be scaled to 96%.

Hi,


We are working on it and will get back to you with feedback soon.

Best Regards,

are you able to reproduce the scenario as I described ?

Hi,


I have shared a piece of code in a text file with you. This code will help you to achieve your requirements. I have also shared my generated results with you for your kind reference. Please see attachments. Please share feedback with us if there is still an issue.

Best Regards,

you are using addImage(java.awt.image.BufferedImage p1)



we are using com.aspose.slides.IPPImage addImage(byte[] p1)



it is different API provided in the interface: public interface IImageCollection

extends IGenericCollection





please try the byte array API to reproduce the scenario we have found.





in the example code I show you, all you need to do is:



byte[] imageBytes = IOUtils.loadFileAsByte(path, “testImage.jpg”);



IPPImage imgx = presentation.getImages().addImage(imageBytes);

Hi,

I have tested using loading the image file as byte array and result is still the same on my end using Aspose.Slides for Java 16.12.0. For your kind reference, I have attached the generated presentation and used sample code as well.


public static void TestImageAdd() throws IOException
{
String path=“c:\Aspose Data\Test\”;
Presentation presentation = new Presentation(“c:\Aspose Data\Test\EmptyPage.pptx”);

//byte[] imageBytes = IOUtils.loadFileAsByte( path+“testImage.jpg”);
Path fileLocation = Paths.get(path+“testImage.jpg”);
byte[] imageBytes = Files.readAllBytes(fileLocation);

IPPImage imgx = presentation.getImages().addImage(imageBytes);
ISlideCollection slides = presentation.getSlides();
IGlobalLayoutSlideCollection layoutSlides = presentation.getLayoutSlides();
ILayoutSlide layoutSlide = layoutSlides.get_Item(0);
ISlide islide = slides.addEmptySlide(layoutSlide);

PictureFrame pf =
(PictureFrame)islide.getShapes().addPictureFrame(ShapeType.Rectangle, 10, 20, imgx.getWidth(), imgx.getHeight(), imgx);
pf.setRelativeScaleHeight(1.0f);
pf.setRelativeScaleWidth(1.0f);
presentation.save(path+“SavedFile.pptx”, SaveFormat.Pptx);
}

Many Thanks,

I have tested with the code you have provided. I have not changed anything besides the file location. I am using Aspose.Slides 16.12.0, I still get 96% as the result. Have you tested in Linux box? We are working on Linux box. our java version is jdk17. let me know if you need any more information.

Hi,

I have observed your comments. Can you please share the generated output that you obtained using Aspose.Slides for Java 16.12.0 on your end.

Many Thanks,

Hi,


I have worked again with your issue. I like to inform that this issue is appearing owing to display setting on your end. I have also shared screenshot for your kind reference. Please see attachments.

Best Regards,

Right click the file I attached -> 7-zip open archive;

Open the Presentation.xml, we can see the file is generated by Aspose.Slides for Java 16.12.0.0.



if you open the file with PowerPoint, check the image size, you will see both height and width are scaled at 96%.



I am using the code you provided. did not add any other code.



Please investigate.

Hi,


I have observed your comments. I like to inform that i was facing similar issue on my end however when i changed my display settings from window settings and set window scaling at 100% like i shared screen shot and then generate result it was according to our desired output and scaling was at 100%. Can you please confirm that you have tried this display settings option.

Best Regards,

When I view the generated pptx on my Windows box, my current Windows OS display scale settings are at 100%. However, I am curious why Aspose.Slides(?) would use the Windows OS display settings. Since I am utilizing Aspose.Slides on a Linux environment to insert and scale the image, Aspose.Slides would not have access to any of the Windows OS display settings. Furthermore if on the same Linux environment I generated a PDF with Aspose.Slides right after I inserted the scaled image, are you suggesting that the image scale (and size) would be undetermined until it was viewed on a Windows machine?


Besides the curiousity questions above, the simple question I would have is are you able to replicate this problem? If not, have you tried to replicate this problem using a Linux box?

Your help is most appreciated. Thanks

Hi,


I have observed your comment and like to share that I have created an issue with ID SLIDESJAVA-35868 as investigation in our issue tracking system to investigate why Aspose.Slides is getting dependent on display settings. We will share the feedback with you as soon as the issue will be fixed.

We are sorry for your inconvenience,