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?

SysDragon
  • 9,692
  • 15
  • 60
  • 89
ferenyl
  • 181
  • 1
  • 8
  • 2
    Couple examples here: http://stackoverflow.com/questions/1195064/fastest-image-resizing-in-net – Tim M. Feb 21 '13 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 '13 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 '13 at 11:24
  • 1
    Your memory usage will be the same when done correctly either way.. – Simon Whitehead Feb 21 '13 at 11:50

2 Answers2

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.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Lilith River
  • 16,204
  • 2
  • 44
  • 76
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.

Denys Denysenko
  • 7,598
  • 1
  • 20
  • 30