如何在c#.net中调整图像大小而又不降低其质量?

时间:2019-07-15 08:37:12

标签: c# blur loss

如何在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);
}

1 个答案:

答案 0 :(得分:2)

您可以使用重载的Bitmap构造函数来创建新的调整大小的图像,如下所示:

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

然后使用以下命令调用它:

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