Image Resizer is a Nuget package that allows resizing images in .NET in a very simple and efficient way. Hereby I am describing steps to use ImageResizer.
1. Install ImageResizer from NuGet. Either search in the NuGet or run the following command in Visual Studio Package Manager Console -
PM > Install-Package ImageResizer
2. Describe your resize settings as follows -
var imgSettings = new ResizeSettings {
MaxWidth = maxWidthYouWant, // Can be any integer
MaxHeight = maxHeightYouWant, // Can be any integer
Format = formatOfYourChoice // Example - "jpg"
};
// Apply resize settings to the image
// inputStream represents the original image (as FileStream/MemoryStream)
// outputStream represents the output stream after resizing
ImageBuilder.Current.Build(inputStream, outputStream, imgSettings);
var resized = outputStream.ToArray(); // Represents byte array of the image after resizing
Image resizing maynot be simpler than this and that also without performance overhead. And there are some more super cool features you can get here.
No comments:
Post a Comment