Scaling images keeping aspect

Hello,

I'm trying to draw images in a PDF. I need them to fit into a space smaller or bigger than the original size and still maintain the aspect. From what I have gathered in this forum, the recommended method is to draw the image and give a new size like this:
header.Graphics.DrawImage(titleImage, new PointF(0, 0), new SizeF(newWidth, newHeight)); 

The original image is 1190 x 160. The height of the space I want to fill with the image is 100. How do I scale the image to fill that height keeping the aspect?

Thanks.
Alan


1 Reply 1 reply marked as answer

SL Sowmiya Loganathan Syncfusion Team November 9, 2020 12:32 PM UTC

Hi Alan,    
   
Thank you for contacting Syncfusion support.    
   
We have analyzed your requirement to draw an image with a specified size keeping with aspect and we can achieve this by using the below code,    
   
//Load the image from the disk   
PdfBitmap image = new PdfBitmap(imageStream);   
   
//Draw the image   
graphics.DrawImage(image, new RectangleF(0,0,page.GetClientSize().Width,100));   
   
  
While drawing the image to a PDF document, we did not change the aspect ratio of the image file. So kindly use the above code on your end and let us know the result. If you still facing any issue, please provide us the image file, so that we will analyze further and provide the precise solution on this.    
 
Regards, 
Sowmiya Loganathan 


Marked as answer
Loader.
Up arrow icon