简体   繁体   中英

Resize Image in ASP.NET Core 3.1?

I used this code to resize the image

foreach (var file in imgworksample)
{               
        var filesize = Image.FromStream(file.OpenReadStream());                     
        var scaleImage = ImageResize.Scale(filesize, 400, 700);
        scaleImage.SaveAs(imagePath + file.FileName);
        size += file.Length;
}

But it did not work.

What method should I use to resize the image?

Try this. I think it should work.


foreach (var file in imgworksample)
{               
       
        var img = Image.Load(file.OpenReadStream());
        img.Mutate(x => x.Resize(400, 700));
        img.Save(imagePath + file.FileName);
        size += file.Length;
}


Update

Install-Package SixLabors.ImageSharp -IncludePrerelease

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM