Exemplo n.º 1
0
        public static void SaveImage(string path, Bitmap img)
        {
            //ImageCodecInfo iciPng = null;
            //foreach (ImageCodecInfo ici in ImageCodecInfo.GetImageDecoders())
            //{
            //    if (ici.FilenameExtension.ToLower().Contains("png"))
            //    {
            //        iciPng = ici;
            //        break;
            //    }
            //}

            // Jpeg image codec
            ImageCodecInfo pngCodec = ImageExtensions.GetEncoderInfo("image/png");

            if (pngCodec == null)
            {
                throw new Exception("SW Error saving image - png codec not present on computer");
            }

            EncoderParameters eps = new EncoderParameters(1);
            EncoderParameter  ep  = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 32L);

            eps.Param[0] = ep;


            img.Save(path, pngCodec, eps);
        }
Exemplo n.º 2
0
        public static void SaveImageJPG(this Bitmap bmp, string filepath, long quality)
        {
            // Encoder parameter for image quality
            EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);

            // Jpeg image codec
            ImageCodecInfo jpegCodec = ImageExtensions.GetEncoderInfo("image/jpeg");

            if (jpegCodec == null)
            {
                return;
            }

            EncoderParameters encoderParams = new EncoderParameters(1);

            encoderParams.Param[0] = qualityParam;

            bmp.Save(filepath, jpegCodec, encoderParams);
        }