How to resize images before upload using c#Asp.net

Asked

Viewed 946 times

1

I am learning. net mvc 4 and would like to know if there is any good and simple library, to resize images before uploading, I googled and only found complex functions with resizing calculations made in hand. As this is something very common, I believe there is some library ready and functional for this task. Anyone knows any?

2 answers

1

found that the library System.Web.Helpers has a class called WebImage. It is possible to resize the image and save the upload. I just needed a logic to find the right height, because it doesn’t allow you to pass only width or height as a parameter, so the code went like this:

int width = 800;
int height = (int)Math.Round(((width * 1.0) / image.Width) * image.Height);
image.Resize(width, height);
image.Save(path + fileName);

Source: https://stackoverflow.com/questions/14613325/resize-image-width-in-c-sharp-but-not-the-height

0

  • the combination of this library with the component is exactly what I wanted. Thank you Thiago!!

  • Thiago, this library works with the "Fileupload" image of Webforms, I need a library that works with "Httppostedfilebase" of MVC. Do you know if you can adapt or just with another library?

  • for you to make it work with Httppostedfilebase would just add the references System.Web, System.Web.Httppostedfilebase and System.Web.Httppostedfilewrapper, I believe it works well.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.