/// <summary> /// Create a <see cref="MemoryStream"/> from an <see cref="Image"/> instance. /// The <see cref="Image"/> is converted to the specified format and encoding. /// </summary> /// <param name="value">An <see cref="Image"/> instance</param> /// <param name="format">The format for the image</param> /// <param name="encoderParameters">A collection of <see cref="EncoderParameter"/>s to set image quality, colour depth etc</param> /// <returns>An <see cref="Image"/> <see cref="MemoryStream"/> in the specified format and encoding</returns> internal static MemoryStream ToMemoryStream(this Image value, ImageFormat format, EncoderParameters encoderParameters = null) { using (var ms = new MemoryStream()) { value.Save(ms, format.CodecInfo(), encoderParameters); return(ms); } }