简体   繁体   中英

how to resize an image without loosing its quality in c#.net?

how to resize an image without loosing its quality in c#.net ?

Stream myBlob;
var encoder = new JpegEncoder();using (var output = new MemoryStream())
using (SixLabors.ImageSharp.Image<Rgba32> image = Image.Load(myBlob))
{   var divisor = image.Width / 100;
    var height = Convert.ToInt32(Math.Round((decimal)(image.Height/divisor)));
    image.Mutate(x => x.Resize(320, 640));
    image.Save(output, encoder);
    output.Position = 0;
    await blockBlob.UploadFromStreamAsync(output);
}

You can use the overloaded Bitmap constructor to create the new re-sized image, as can be seen bellow:

public static Image Resize(Image image, Size size)
{
   return (Image)(new Bitmap(image, size));
}

And you call it using:

var result = Resize(image, new Size(320,640));

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