简体   繁体   English

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

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

how to resize an image without loosing its quality in c#.net ? 如何在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: 您可以使用重载的Bitmap构造函数来创建新的调整大小的图像,如下所示:

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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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