Exemplo n.º 1
0
 public void GetImageEncoderFromMimeType_StandardSupportedTypes_ReturnsEncoder()
 {
     Assert.AreEqual("BMP", ImageTypeHelper.GetImageEncoderFromMimeType("image/bmp").FormatDescription);
     Assert.AreEqual("JPEG", ImageTypeHelper.GetImageEncoderFromMimeType("image/jpeg").FormatDescription);
     Assert.AreEqual("GIF", ImageTypeHelper.GetImageEncoderFromMimeType("image/gif").FormatDescription);
     Assert.AreEqual("TIFF", ImageTypeHelper.GetImageEncoderFromMimeType("image/tiff").FormatDescription);
     Assert.AreEqual("PNG", ImageTypeHelper.GetImageEncoderFromMimeType("image/png").FormatDescription);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Saves an Image as a JPEG to the given stream using a 1 - 100 compression level
        /// </summary>
        /// <param name="img"></param>
        /// <param name="outputStream"></param>
        /// <param name="compression"></param>
        public static void SaveJpegWithCompressionSetting(this Image img, Stream outputStream, long compression)
        {
            var eps = new EncoderParameters(1);

            eps.Param[0] = new EncoderParameter(Encoder.Quality, compression);
            var ici = ImageTypeHelper.GetImageEncoderFromMimeType("image/jpeg");

            img.Save(outputStream, ici, eps);
        }