Last post Oct 22, 2007 11:05 AM by markbruv1
Oct 05, 2007 08:10 PM|digitalmagik|LINK
Hi, I'm pretty new to ASP.NET but I must say it is so cool so far. Here is my question:
I am trying to write a class that allows a visitor to upload an image file, and then that image needs to be resized to certain dimensions. I have the general method figured out (I think!) but what I really want to know is if I can resize the image
before saving it to disk upon upload. It seems pretty inefficient to save an upload to disk -> reopen the file and put in Image object -> do the necessary work to resize -> then resave it. Can anyone suggest if what I want is possible and if so some
pointers on how to do it?
Oct 05, 2007 09:52 PM|vcsjones|LINK
Yeah, you can modify the image before saving it to disk. What you can do is create an instance of a
Bitmap class that takes a stream in as a constructor parameter... so in theory you can create an instance of a Bitmap class on the stream of file being uploaded using the FileUpload control. Then, resize your bitmap, then save it to disk.
There are a lot of good pointers about resizing images in this thread that you may find useful and lots of good code samples:
Oct 05, 2007 09:58 PM|robert.westerlund|LINK
Sure thing. I suppose you are using the FileUpload control. From the FileUpload control, you can get a stream via the FileContent property. Using that stream, you can get an image using Image.FromStream and with that Image, you can resize the image and save
it to disk.
Oct 05, 2007 10:33 PM|vcsjones|LINK
Sorry, my last reply was a little lazy. I created a sample web application that allows people to upload an image, and it resizes it to 50% before saving it to disk.. while the application is pretty simple, it demonstrates what you are looking for.
Download it here:
Oct 06, 2007 04:50 PM|digitalmagik|LINK
Thanks boys! So far everything is looking good. I'm leaving this thread open though for the time being until I'm fully sure I'm 100% on the subject. But thank you so much so far! [:D]
Oct 11, 2007 12:36 AM|officialboss|LINK
Download it here:
Great example, thanks!
Oct 22, 2007 11:05 AM|markbruv1|LINK
This works perfectly, thank you [:)]