Пример #1
0
        public void Save(string filename, ImageFormat format)
        {
            ImageCodecInfo codecInfo = GetCodecInfo(format);

            if (codecInfo == null)
            {
                throw new SystemException(codecInfo.CodecName + " codec isn't installed");
            }

            EncoderParameters pars = null;

            if (format == ImageFormat.Jpeg)
            {
                FormJpgQuality fjpg = new FormJpgQuality("Qualità Jpeg", 100);
                if (fjpg.ShowDialog(this) == DialogResult.Cancel)
                {
                    return;
                }

                pars          = new EncoderParameters(1);
                pars.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, fjpg.JpegQuality);
            }
            else if (format == ImageFormat.Bmp)
            {
                pars          = new EncoderParameters(1);
                pars.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 24);
            }
            else if (format == ImageFormat.Png)
            {
                pars          = new EncoderParameters(1);
                pars.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 32);
            }

            if (pars == null)
            {
                _img.Save(filename, format);
            }
            else
            {
                _img.Save(filename, codecInfo, pars);
            }
        }
Пример #2
0
        public void Save(string filename, ImageFormat format)
        {
            ImageCodecInfo codecInfo = GetCodecInfo(format);

            if (codecInfo == null)
            {
                throw new SystemException(codecInfo.CodecName + " codec isn't installed");
            }

            EncoderParameters pars = null;

            if (format == ImageFormat.Jpeg)
            {
                FormJpgQuality fjpg = new FormJpgQuality("Qualità Jpeg",100);
                if (fjpg.ShowDialog(this) == DialogResult.Cancel) return;

                pars = new EncoderParameters(1);
                pars.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality,fjpg.JpegQuality);
            }
            else if (format== ImageFormat.Bmp)
            {
                pars = new EncoderParameters(1);
                pars.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 24);
            }
            else if (format == ImageFormat.Png)
            {
                pars = new EncoderParameters(1);
                pars.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 32);
            }

            if (pars == null)
            {
                _img.Save(filename, format);
            }
            else
            {
                _img.Save(filename, codecInfo, pars);
            }
        }