Hi ,
Please review the attached files here.
For Support-ImageSize-Scaling-Issue.zip (138.6 KB)
We have an issue when we place an image in the power point slide using aspose.slides. Issue is with the quality of the image as compared to the “PDF output”(refer file named “File-PDF-SameOutput.pdf”) or even with the “Orignial Image”(refer file named “Original Image used in PPTX and PDF.emf”).
Basically, both pdf output(on 100% zoom) and original image looks too good which as of now our clients are using. So, now we are trying to generate the same images/reports using Aspose.Slides in PPTX and the quality of the image in the PPTX(refer file named “FileWith-Default Scaling.pptx”) does not match with the PDF output. So we are worried that it may not be accepted by our customers.
So, please let us know, is there any way that we can generate the PPTX with the best quality or to match with pdf output quality/original image.
We tried few options to scale the image in PPTX itself but we couldn’t figure it out. Also, we tried to generate the PPTX with the slide having same scaling as image(refer file name “FileWith-Original-Image-Scaling-1056-816.pptx”), But the image is getting cropped and cannot view the image completely even thought the quality looks better here.
Please let us know a proper way to handle this issue considering will be generating more than 50,000 reports quarterly in our production and the quality of the image output is critical for our clients.
Thanks in Advance.
Prathap
@PrathapSV,
Thank you for posting the query. Aspose.Slides does not change images when adding them to presentations. Moreover, EMF is the vector format. This format does not lose quality when scaled. But the final image displaying (rendering) depends on the viewing application (PowerPoint, Adobe Acrobat Reader, browsers, etc). It may also depend on the display settings in the operating system.
Unfortunately, I found no problems with the image quality. Also, PDF viewers and PPTX viewers can display the image differently.
I agree that we can’t compare the output of PDF and PPTX since they are two different viewers and has their own rendering engine. But is there any other things/best practices to follow while adding the image to the picture frame/slide?
Can you recommend the best settings(Size, resolution or any other powerpoint level properties if any) to apply when we add the image to the slide?
As of now we are considering the size of the slide and creating the picture frame and adding the image to the picture frame. Below is the code for your reference.
Please let us know if we can do anything to best fit the image to the slide size to get the maximum quality while viewing the slide.
private ISlide AddSlideAsposeSlides(Presentation presentation, ISlide asposeFirstDefaultSlide, string imagePath, int slideIndex)
{
ISlide asposeSlide = presentation.Slides.InsertClone(slideIndex, asposeFirstDefaultSlide);
float left = 0;
float top = 0;
float width = presentation.SlideSize.Size.Width;
float height = presentation.SlideSize.Size.Height;
byte[] bufferData = File.ReadAllBytes(imagePath);
IPPImage imgx = presentation.Images.AddImage(bufferData);
asposeSlide.Shapes.AddPictureFrame(ShapeType.Rectangle, left, top, width, height, imgx);
//asposeSlide.Shapes[1].LockAspectRatio = MsoTriState.msoTrue;
return asposeSlide;
}
Thanks,
Prathap
@PrathapSV,
I would not recommend that you set the slide size for images. This will lead to unwanted transformations (compressions and stretches along the axes). For the best display of the image on the slide, I would suggest that you keep its aspect ratio. You can do it like this:
using (var presentation = new Presentation())
{
float slideWidth = presentation.SlideSize.Size.Width;
float slideHeight = presentation.SlideSize.Size.Height;
var imageData = File.ReadAllBytes(imageFilePath);
var image = presentation.Images.AddImage(imageData);
int imageWidth = image.Width;
int imageHeight = image.Height;
SizeF finalSize = GetMaxProportionalImageSize(slideWidth, slideHeight, imageWidth, imageHeight);
PointF finalPosition = GetImageCenterPosition(slideWidth, slideHeight, finalSize);
presentation.Slides[0].Shapes.AddPictureFrame(
ShapeType.Rectangle, finalPosition.X, finalPosition.Y, finalSize.Width, finalSize.Height, image);
presentation.Save("test.pptx", SaveFormat.Pptx);
}
static SizeF GetMaxProportionalImageSize(float slideWidth, float slideHeight, float imageWidth, float imageHeight)
{
float finalHeight = slideHeight;
float heightRatio = slideHeight / imageHeight;
float finalWidth = imageWidth * heightRatio;
if (finalWidth > slideWidth)
{
finalWidth = slideWidth;
float widthRatio = slideWidth / imageWidth;
finalHeight = imageHeight * widthRatio;
}
return new SizeF(finalWidth, finalHeight);
}
static PointF GetImageCenterPosition(float slideWidth, float slideHeight, SizeF imageSize)
{
float x = (slideWidth - imageSize.Width) / 2;
float y = (slideHeight - imageSize.Height) / 2;
return new PointF(x, y);
}