Resizing image proportionally in ASP.NET C# by specifying either Height or Width

后端 未结 5 790
一整个雨季
一整个雨季 2021-02-11 07:33

I need a code that will allow me to resize images, but with the following functionality:

1) resize image upon upload

2) Resize image proportionally by specifying

5条回答
  •  星月不相逢
    2021-02-11 07:56

    Although it seems like you should be able to copy and paste a snippet to do this, there are a ton of pitfalls you need to look out for if you're building your own image resizing system. It's better to use a proven, tested, and supported open-source library.

    To resize to a file directly from HttpPostedFile, call

    ImageBuilder.Current.Build(httpPostedFile, "img.jpg", new ResizeSettings("width=200&quality=90"));
    

    To resize an existing file, call

    ImageBuilder.Current.Build("orig.jpg", "img.jpg", new ResizeSettings("width=200&quality=90"));
    

    The ImageResizing.Net library is free, and MIT-licensed (no worries about licensing problems).

提交回复
热议问题