DEBUG and RELEASE modeI have an image with resolution 2304x1528 (ratio: 1.50785...). I want to save it with width 300px preserving original aspect ratio. However passing height = 0 to ResizeOptions.Size, and setting mode Min/Maxmakes result image with width 299px.
To workaround the issue I calc height manualy like that (using Ceiling method before conversion to int) and pass it to Size:
Convert.ToInt32(Math.Ceiling(resizeOptions.Width / image.PixelRatio))
using (Image<Rgba32> image = Image.Load("foo.jpg"))
{
image
.Resize(new ResizeOptions {
Size = new Size(300, 0),
Mode = ResizeMode.Max
})
.Save("bar.jpg");
}
Hey @vad3x thanks for the raising the issue and providing a great code sample for reproduction.
I've pushed a fix for the issue just now so you should now get the correct values.
Cheers
James
Hi @JimBobSquarePants, thanks for the fast response!
The case works well now, but now when I resizing image 1528x2304, I'm getting wierd result.
The image var seems well to me (take a look at width, height):

However, after saving:
Could you please check it, and correct me if I'm wrong?
my guess is you have an image that's been rotated using metadata, I bet that if you inspected the image in both Explorer and ImageSharp before the resize it will also have the dimensions inverted.
I recon is you change your code to
c#
using (Image<Rgba32> image = Image.Load("foo.jpg"))
{
image
.AutoOrient() // <- fixes the pixel data orientation if the metadata differs to it.
.Resize(new ResizeOptions {
Size = new Size(300, 0),
Mode = ResizeMode.Max
})
.Save("bar.jpg");
}
@tocsoft you are right, I've rotated the image using MS Photos app, I did not know that the app changes only metadata.
Thanks Scott.
Most helpful comment
my guess is you have an image that's been rotated using metadata, I bet that if you inspected the image in both Explorer and ImageSharp before the resize it will also have the dimensions inverted.
I recon is you change your code to
c# using (Image<Rgba32> image = Image.Load("foo.jpg")) { image .AutoOrient() // <- fixes the pixel data orientation if the metadata differs to it. .Resize(new ResizeOptions { Size = new Size(300, 0), Mode = ResizeMode.Max }) .Save("bar.jpg"); }