How to "force" width and height in AdaptativeResize method
Posted: 2014-07-11T13:02:18-07:00
Hi,
We have an application responsible for resizing images that are uploaded by the users. The new dimensions are predefined and for each uploaded image, the application creates a new image file for each of the predefined dimensions.
The problem is: The dimensions of the new images doesn't match the values that were specified to the resize method. For example:
The informed values are 60x45, but the image generated is 60x38, 60x36, etc... depending on the dimensions of the original image.
At first, I tried the .Resize method instead of .AdaptativeResize, but the result was the same. Since I wasn't sure if this is the expected behavior or not, I searched the documentation but couldn't understand the situation yet.
Do you guys know if there is a way to 'force' the new image to respect the determined width and height or not? Bellow is the application code:
Thanks in advance,
We have an application responsible for resizing images that are uploaded by the users. The new dimensions are predefined and for each uploaded image, the application creates a new image file for each of the predefined dimensions.
The problem is: The dimensions of the new images doesn't match the values that were specified to the resize method. For example:
Code: Select all
image.AdaptiveResize(60, 45);
At first, I tried the .Resize method instead of .AdaptativeResize, but the result was the same. Since I wasn't sure if this is the expected behavior or not, I searched the documentation but couldn't understand the situation yet.
Do you guys know if there is a way to 'force' the new image to respect the determined width and height or not? Bellow is the application code:
Code: Select all
using (MagickImage image = new MagickImage(originalImagePath))
{
image.Format = MagickFormat.Pjpeg;
image.AnimationDelay = 50;
image.Quality = 60;
image.Depth = 8;
image.AdaptiveResize(newWidth, newHeight);
using (FileStream fs = new FileStream(newImagePath, FileMode.Create))
{
image.Write(fs);
}
}