Ejemplo n.º 1
0
        // From SaveImageToFile, JpegCompress
        public static byte[] EncodeImage(Image image, ImageFormat destFormat, int quality = 80)
        {
            byte[] imageBytes;

            if ((destFormat == null) || (image.RawFormat.Equals(destFormat)))
            {
                imageBytes = ImageTools.ByteArrayFromImage(image);
            }
            else
            {
                EncoderParameters encoderParams = null;

                if (destFormat.Equals(ImageFormat.Jpeg))
                {
                    // quality is used by Jpeg and probably ignored by other formats
                    encoderParams          = new EncoderParameters(1);
                    encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
                }

                imageBytes = ImageTools.EncodeImageParams(image, destFormat, encoderParams);
            }

            return(imageBytes);
        }
Ejemplo n.º 2
0
        private static byte[] EncodeImageParams(Image image, ImageFormat format, EncoderParameters encoderParams)
        {
            System.Diagnostics.Debug.Assert(format != null);

            byte[] result = null;

            ImageCodecInfo codecInfo = GetEncoderInfo(format);

            if (codecInfo != null)
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    image.Save(stream, codecInfo, encoderParams);
                    result = stream.ToArray();
                }
            }
            else
            {
                // Default image native data to byte array without encoding
                result = ImageTools.ByteArrayFromImage(image);
            }

            return(result);
        }
Ejemplo n.º 3
0
 public ImageInfo Clone()
 {
     return(new ImageInfo(ImageTools.ImageClone(fSystemImage)));
 }
Ejemplo n.º 4
0
 public ImageInfo GetThumbnail(int maxWidth, int maxHeight)
 {
     return(new ImageInfo(ImageTools.CreateThumbnail(fSystemImage, maxWidth, maxHeight)));
 }