Exemple #1
0
        private (ImageCodecInfo codec, EncoderParameters pars) getEncoder(NFXImageFormat format)
        {
            ImageCodecInfo    codec;
            EncoderParameters pars;

            if (format is BitmapImageFormat)
            {
                codec         = ImageCodecInfo.GetImageEncoders().First(c => c.FormatID == System.Drawing.Imaging.ImageFormat.Bmp.Guid);
                pars          = new EncoderParameters(1);
                pars.Param[0] = new EncoderParameter(Encoder.ColorDepth, format.Colors);
            }
            else if (format is PngImageFormat)
            {
                codec = ImageCodecInfo.GetImageEncoders().First(c => c.FormatID == System.Drawing.Imaging.ImageFormat.Png.Guid);
                pars  = null;//new EncoderParameters(0);
            }
            else if (format is GifImageFormat)
            {
                codec = ImageCodecInfo.GetImageEncoders().First(c => c.FormatID == System.Drawing.Imaging.ImageFormat.Gif.Guid);
                pars  = null;//new EncoderParameters(0);
            }
            else//default is JPEG
            {
                var jpeg = format as JpegImageFormat;
                codec         = ImageCodecInfo.GetImageEncoders().First(c => c.FormatID == System.Drawing.Imaging.ImageFormat.Jpeg.Guid);
                pars          = new EncoderParameters(1);
                pars.Param[0] = new EncoderParameter(Encoder.Quality, jpeg?.Quality ?? 80L);
            }


            return(codec : codec, pars : null);
        }
Exemple #2
0
        public void Save(Stream stream, NFXImageFormat format)
        {
            var(codec, pars) = getEncoder(format);

            using (var copy = makeSaveCopy())
                copy.Save(stream, codec, pars);
        }
Exemple #3
0
        public void Save(string fileName, NFXImageFormat format)
        {
            var(codec, pars) = getEncoder(format);

            using (var copy = makeSaveCopy())
                copy.Save(fileName, codec, pars);
        }
Exemple #4
0
 public byte[] Save(NFXImageFormat format)
 {
     using (var ms = new MemoryStream())
     {
         this.Save(ms, format);
         return(ms.ToArray());
     }
 }
Exemple #5
0
 public void Save(Stream stream, NFXImageFormat format)
 {
     var(codec, pars) = getEncoder(format);
     m_Bitmap.Save(stream, codec, pars);
 }
Exemple #6
0
 public void Save(string fileName, NFXImageFormat format)
 {
     var(codec, pars) = getEncoder(format);
     m_Bitmap.Save(fileName, codec, pars);
 }