We have recently started using ImageResizer.Net over GDI+ for dynamically resizing images on our ASP.NET MVC 4 application.
Is there a way, using only ImageResizer, to determine the actual resolution(DPI,PPI, whatever you want to call it), of the image (which is read in as a byte array). We currently have a workflow like this, to resize the image to a specified lower resolution when needed:
//pseudo-code
var image = (Bitmap)Bitmap.FromStream(contentStream)
var resX = image.HorizontalResolution;
var resY = image.VerticalResolution;
//calculate scale factor
//determine newHeight and newWidth from scale
var settings = new ResizeSettings("width={newWidth}&height={newHeight}")
var newImage = ImageBuilder.Current.Build(image, someNewImage, settings);
This works fine, but its mixing GDI+ and ImageResizer, and has alot of stream opening and closing of the same data (the actual code is a bit more verbose, with many using statements).
Is there a way to determine the Horizontal and Vertical Resolution using just ImageResizer? I couldn’t immediately find anything in the documentation.
For the moment, we have used the managed api, but will eventually use the MVC routing.
This is a rather atypical scenario – normally incoming DPI values are worthless.
However, since it appears you control those values, and need them to perform sizing calculations, I suggest a plugin. They’re easy, and offer ideal performance since you’re not duplicating effort.
Installation can be done through code or via Web.Config.
new CustomSizing().Install(Config.Current);
or in the resizer’s configuration section: