How to resize an Image C#

前端 未结 17 2633
暗喜
暗喜 2020-11-21 22:28

As Size, Width and Height are Get() properties of System.Drawing.Image;
How can I resize an Image object

17条回答
  •  野的像风
    2020-11-21 23:15

    Note: this will not work with ASP.Net Core because WebImage depends on System.Web, but on previous versions of ASP.Net I used this snippet many times and was useful.

    String ThumbfullPath = Path.GetFileNameWithoutExtension(file.FileName) + "80x80.jpg";
    var ThumbfullPath2 = Path.Combine(ThumbfullPath, fileThumb);
    using (MemoryStream stream = new MemoryStream(System.IO.File.ReadAllBytes(fullPath)))
    {
          var thumbnail = new WebImage(stream).Resize(80, 80);
          thumbnail.Save(ThumbfullPath2, "jpg");
    }
    

提交回复
热议问题