ImageFactory

The ImageFactory class provides methods to perform various manipulation functions on a given image. It has been carefully designed to prevent the various memory leaks that commonly occur when dealing with images in a performant manner. This makes it safe to use on both Desktop and Web environments.

The ImageFactory auto detects the correct file type of the given image and API for the class is fluent which allows you to easily chain methods to deliver the desired output. For example, the following code loads, resizes, sets a new format and saves the MemoryStream containing image information.


Example Code

byte[] photoBytes = File.ReadAllBytes(file);
// Format is automatically detected though can be changed.
ISupportedImageFormat format = new JpegFormat { Quality = 70 };
Size size = new Size(150, 0)
using (MemoryStream inStream = new MemoryStream(photoBytes))
{
    using (MemoryStream outStream = new MemoryStream())
    {
        // Initialize the ImageFactory using the overload to preserve EXIF metadata.
        using (ImageFactory imageFactory = new ImageFactory(preserveExifData:true))
        {
            // Load, resize, set the format and quality and save an image.
            imageFactory.Load(inStream)
                        .Resize(size)
                        .Format(format)
                        .Save(outStream);
        }
        // Do something with the stream.
    }
}