示例#1
0
        public void SendSmallImage(string fileName, int maxHeight, int maxWidth)
        {
            Image image = null;

            this._outBmp = null;
            Graphics graphics = null;

            try
            {
                image = Image.FromFile(fileName);
                ImageFormat rawFormat = image.RawFormat;
                Size        size      = PIC.NewSize(maxWidth, maxHeight, image.Width, image.Height);
                this._outBmp = new Bitmap(size.Width, size.Height);
                graphics     = Graphics.FromImage(this._outBmp);
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.SmoothingMode      = SmoothingMode.HighQuality;
                graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                graphics.DrawImage(image, new Rectangle(0, 0, size.Width, size.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
                graphics?.Dispose();
            }
            catch
            {
            }
            finally
            {
                graphics?.Dispose();
                image?.Dispose();
            }
        }
示例#2
0
        public static void SendSmallImage(string fileName, string newFile, int maxHeight, int maxWidth)
        {
            Image    image    = null;
            Bitmap   bitmap   = null;
            Graphics graphics = null;

            try
            {
                image = Image.FromFile(fileName);
                ImageFormat rawFormat = image.RawFormat;
                Size        size      = PIC.NewSize(maxWidth, maxHeight, image.Width, image.Height);
                bitmap   = new Bitmap(size.Width, size.Height);
                graphics = Graphics.FromImage(bitmap);
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.SmoothingMode      = SmoothingMode.HighQuality;
                graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                graphics.DrawImage(image, new Rectangle(0, 0, size.Width, size.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
                graphics?.Dispose();
                EncoderParameters encoderParameters = new EncoderParameters();
                long[]            value             = new long[1]
                {
                    100L
                };
                EncoderParameter encoderParameter = new EncoderParameter(Encoder.Quality, value);
                encoderParameters.Param[0] = encoderParameter;
                ImageCodecInfo[] imageEncoders  = ImageCodecInfo.GetImageEncoders();
                ImageCodecInfo   imageCodecInfo = null;
                int num = 0;
                while (num < imageEncoders.Length)
                {
                    if (!imageEncoders[num].FormatDescription.Equals("JPEG"))
                    {
                        num++;
                        continue;
                    }
                    imageCodecInfo = imageEncoders[num];
                    break;
                }
                if (imageCodecInfo != null)
                {
                    bitmap.Save(newFile, imageCodecInfo, encoderParameters);
                }
                else
                {
                    bitmap.Save(newFile, rawFormat);
                }
            }
            catch
            {
            }
            finally
            {
                graphics?.Dispose();
                image?.Dispose();
                bitmap?.Dispose();
            }
        }
示例#3
0
文件: PIC.cs 项目: llenroc/kangaroo
 public void SendSmallImage(string fileName, int maxHeight, int maxWidth)
 {
     System.Drawing.Image image = null;
     this._outBmp = null;
     System.Drawing.Graphics graphics = null;
     try
     {
         image = System.Drawing.Image.FromFile(fileName);
         System.Drawing.Imaging.ImageFormat arg_18_0 = image.RawFormat;
         System.Drawing.Size size = PIC.NewSize(maxWidth, maxHeight, image.Width, image.Height);
         this._outBmp = new System.Drawing.Bitmap(size.Width, size.Height);
         graphics     = System.Drawing.Graphics.FromImage(this._outBmp);
         graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
         graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
         graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
         graphics.DrawImage(image, new System.Drawing.Rectangle(0, 0, size.Width, size.Height), 0, 0, image.Width, image.Height, System.Drawing.GraphicsUnit.Pixel);
         if (graphics != null)
         {
             graphics.Dispose();
         }
     }
     catch
     {
     }
     finally
     {
         if (graphics != null)
         {
             graphics.Dispose();
         }
         if (image != null)
         {
             image.Dispose();
         }
     }
 }
示例#4
0
文件: PIC.cs 项目: llenroc/kangaroo
 public static void SendSmallImage(string fileName, string newFile, int maxHeight, int maxWidth)
 {
     System.Drawing.Image    image    = null;
     System.Drawing.Bitmap   bitmap   = null;
     System.Drawing.Graphics graphics = null;
     try
     {
         image = System.Drawing.Image.FromFile(fileName);
         System.Drawing.Imaging.ImageFormat rawFormat = image.RawFormat;
         System.Drawing.Size size = PIC.NewSize(maxWidth, maxHeight, image.Width, image.Height);
         bitmap   = new System.Drawing.Bitmap(size.Width, size.Height);
         graphics = System.Drawing.Graphics.FromImage(bitmap);
         graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
         graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
         graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
         graphics.DrawImage(image, new System.Drawing.Rectangle(0, 0, size.Width, size.Height), 0, 0, image.Width, image.Height, System.Drawing.GraphicsUnit.Pixel);
         if (graphics != null)
         {
             graphics.Dispose();
         }
         System.Drawing.Imaging.EncoderParameters encoderParameters = new System.Drawing.Imaging.EncoderParameters();
         long[] value = new long[]
         {
             100L
         };
         System.Drawing.Imaging.EncoderParameter encoderParameter = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, value);
         encoderParameters.Param[0] = encoderParameter;
         System.Drawing.Imaging.ImageCodecInfo[] imageEncoders  = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders();
         System.Drawing.Imaging.ImageCodecInfo   imageCodecInfo = null;
         for (int i = 0; i < imageEncoders.Length; i++)
         {
             if (imageEncoders[i].FormatDescription.Equals("JPEG"))
             {
                 imageCodecInfo = imageEncoders[i];
                 break;
             }
         }
         if (imageCodecInfo != null)
         {
             bitmap.Save(newFile, imageCodecInfo, encoderParameters);
         }
         else
         {
             bitmap.Save(newFile, rawFormat);
         }
     }
     catch
     {
     }
     finally
     {
         if (graphics != null)
         {
             graphics.Dispose();
         }
         if (image != null)
         {
             image.Dispose();
         }
         if (bitmap != null)
         {
             bitmap.Dispose();
         }
     }
 }
示例#5
0
文件: PIC.cs 项目: tyriankid/WFX
        public static void SendSmallImage(string fileName, string newFile, int maxHeight, int maxWidth)
        {
            Image    image    = null;
            Bitmap   bitmap   = null;
            Graphics graphics = null;

            try
            {
                image = Image.FromFile(fileName);
                ImageFormat rawFormat = image.RawFormat;
                Size        size      = PIC.NewSize(maxWidth, maxHeight, image.Width, image.Height);
                bitmap   = new Bitmap(size.Width, size.Height);
                graphics = Graphics.FromImage(bitmap);
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.SmoothingMode      = SmoothingMode.HighQuality;
                graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                graphics.DrawImage(image, new Rectangle(0, 0, size.Width, size.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
                if (graphics != null)
                {
                    graphics.Dispose();
                }
                EncoderParameters encoderParams = new EncoderParameters();
                long[]            numArray      = new long[]
                {
                    100L
                };
                EncoderParameter parameter = new EncoderParameter(Encoder.Quality, numArray);
                encoderParams.Param[0] = parameter;
                ImageCodecInfo[] imageEncoders = ImageCodecInfo.GetImageEncoders();
                ImageCodecInfo   encoder       = null;
                for (int i = 0; i < imageEncoders.Length; i++)
                {
                    if (imageEncoders[i].FormatDescription.Equals("JPEG"))
                    {
                        encoder = imageEncoders[i];
                        break;
                    }
                }
                if (encoder != null)
                {
                    bitmap.Save(newFile, encoder, encoderParams);
                }
                else
                {
                    bitmap.Save(newFile, rawFormat);
                }
            }
            catch
            {
            }
            finally
            {
                if (graphics != null)
                {
                    graphics.Dispose();
                }
                if (image != null)
                {
                    image.Dispose();
                }
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }
            }
        }