Search code examples
imageresizer

ImageResizer - What is the method to render an image to the browser?


I've just started experimenting with ImageResizer. Everything has worked great so far. But I've yet to find a way to render an image to the browser in my MVC code. At the moment I'm using WebImage to do it, as follows:

  WebImage webImage = new WebImage(image);
  webImage.Write();

WebImage is included in System.Web.Helpers. I'd like to have ImageResizer do this if it can.


Solution

  • ImageResizer's ImageJob class can read/write from any Stream instance.

    You can provide a MemoryStream or Response.OutputStream to have ImageResizer write it directly to output, similar to how WebImage does.

    However, using ImageResizer within an MVC action is not a best practice. You are sacrificing disk caching and quite a bit of performance, as well as compatibility with many of the plugins.