2

I'm looking for a way to resize images without saving them on the server. The ways that i have found includes a controller file and such.

Is there a way to get the image from the stream, resize it and add it to the response?

4
  • 2
    Couple examples here: stackoverflow.com/questions/1195064/…
    – Tim M.
    Feb 21, 2013 at 10:50
  • 1
    This is VERY BAD IDEA! If you will get a lot of images at the one, you will get out of memory exception! Because your images will store in memory.
    – Maris
    Feb 21, 2013 at 10:51
  • Maris, this is only experimental so the memory isn't really an issue. But i hope others will see this comment.
    – ferenyl
    Feb 21, 2013 at 11:24
  • 1
    Your memory usage will be the same when done correctly either way.. Feb 21, 2013 at 11:50

2 Answers 2

4

Check out ImageResizer - it's a suite of NuGet packages designed for this exact purpose.

It runs eBay in Denmark, MSN Olympics, and a few other big sites.

Dynamic image processing can be done safely and efficiently, but not in a sane amount of code. It's trickier than it appears.

2

I wouldn't recommend this but you can do next thing:

using (Image img = Image.FromStream(originalImage))
{
    using (Bitmap bitmap = new Bitmap(img, width, height))
    {
        bitmap.Save(outputStream, ImageFormat.Jpeg);
    }
}

Be aware that this could cause OutOfMemoryException.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.