Welcome Guest! To enable all features, please Login or Register.



Last Go to last post Unread Go to first unread post
#1 Posted : Wednesday, June 12, 2019 10:02:09 AM(UTC)


Groups: Manager, Tech Support, Administrators
Posts: 218

Was thanked: 12 time(s) in 12 post(s)

If you need to determine if an image needs to be resized to fit within a rectangle, then you can use the following method:

      public static void ResizeAspectRatio(RasterImage img, int canvasWidth, int canvasHeight)
         // image is smaller than the canvas so no need to resize
         if (img.Width < canvasWidth && img.Height < canvasHeight)

         // Figure out the ratio
         double ratioX = (double)canvasWidth / (double)img.Width;
         double ratioY = (double)canvasHeight / (double)img.Height;
         // use whichever multiplier is smaller
         double ratio = ratioX < ratioY ? ratioX : ratioY;

         // now we can get the new height and width
         int newHeight = Convert.ToInt32(img.Height * ratio);
         int newWidth = Convert.ToInt32(img.Width * ratio);

         //Resize the image
         SizeCommand sizeCommand = new SizeCommand(newWidth, newHeight, RasterSizeFlags.Resample);
Hadi Chami
Developer Support Manager
LEAD Technologies, Inc.


Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2023, Yet Another Forum.NET
This page was generated in 0.069 seconds.