Beispiel #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();
            }
        }
Beispiel #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();
            }
        }
Beispiel #3
0
 protected void Page_Load(object sender, System.EventArgs e)
 {
     try
     {
         string virtualPath = string.Empty;
         int    maxWidth    = 0;
         int    maxHeight   = 0;
         if (PicRar.IsQueryString("P", "S"))
         {
             virtualPath = base.Request.QueryString["P"];
         }
         if (PicRar.IsQueryString("W"))
         {
             maxWidth = int.Parse(base.Request.QueryString["W"]);
         }
         if (PicRar.IsQueryString("H"))
         {
             maxHeight = int.Parse(base.Request.QueryString["H"]);
         }
         if (virtualPath != string.Empty)
         {
             PIC pic = new PIC();
             if (!virtualPath.StartsWith("/"))
             {
                 virtualPath = "/" + virtualPath;
             }
             virtualPath = Globals.ApplicationPath + virtualPath;
             pic.SendSmallImage(base.Request.MapPath(virtualPath), maxHeight, maxWidth);
             string watermarkFilename      = base.Request.MapPath(Globals.ApplicationPath + "/Admin/images/watermark.gif");
             System.IO.MemoryStream stream = pic.AddImageSignPic(pic.OutBMP, watermarkFilename, 9, 60, 4);
             pic.Dispose();
             base.Response.ClearContent();
             base.Response.ContentType = "image/gif";
             base.Response.BinaryWrite(stream.ToArray());
             base.Response.End();
             stream.Dispose();
         }
     }
     catch (System.Exception exception)
     {
         this.label_html = exception.Message;
     }
 }
Beispiel #4
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         string virtualPath = string.Empty;
         int maxWidth = 0;
         int maxHeight = 0;
         if (IsQueryString("P", "S"))
         {
             virtualPath = Request.QueryString["P"];
         }
         if (IsQueryString("W"))
         {
             maxWidth = int.Parse(Request.QueryString["W"]);
         }
         if (IsQueryString("H"))
         {
             maxHeight = int.Parse(Request.QueryString["H"]);
         }
         if (virtualPath != string.Empty)
         {
             PIC pic = new PIC();
             if (!virtualPath.StartsWith("/"))
             {
                 virtualPath = "/" + virtualPath;
             }
             virtualPath = Globals.ApplicationPath + virtualPath;
             pic.SendSmallImage(Request.MapPath(virtualPath), maxHeight, maxWidth);
             string watermarkFilename = Request.MapPath(Globals.ApplicationPath + "/Admin/images/watermark.gif");
             MemoryStream stream = pic.AddImageSignPic(pic.OutBMP, watermarkFilename, 9, 60, 4);
             pic.Dispose();
             Response.ClearContent();
             Response.ContentType = "image/gif";
             Response.BinaryWrite(stream.ToArray());
             Response.End();
             stream.Dispose();
         }
     }
     catch (Exception exception)
     {
         label_html = exception.Message;
     }
 }
Beispiel #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         string text      = string.Empty;
         int    maxWidth  = 0;
         int    maxHeight = 0;
         if (PicRar.IsQueryString("P", "S"))
         {
             text = base.Request.QueryString["P"];
         }
         if (PicRar.IsQueryString("W"))
         {
             maxWidth = int.Parse(base.Request.QueryString["W"]);
         }
         if (PicRar.IsQueryString("H"))
         {
             maxHeight = int.Parse(base.Request.QueryString["H"]);
         }
         if (!(text == string.Empty))
         {
             PIC pIC = new PIC();
             if (!text.StartsWith("/"))
             {
                 text = "/" + text;
             }
             text = text;
             pIC.SendSmallImage(base.Request.MapPath(text), maxHeight, maxWidth);
             string       watermarkFilename = base.Request.MapPath("/Admin/images/watermark.gif");
             MemoryStream memoryStream      = pIC.AddImageSignPic(pIC.OutBMP, watermarkFilename, 9, 60, 4);
             pIC.Dispose();
             base.Response.ClearContent();
             base.Response.ContentType = "image/gif";
             base.Response.BinaryWrite(memoryStream.ToArray());
             base.Response.End();
             memoryStream.Dispose();
         }
     }
     catch (Exception ex)
     {
         this.label_html = ex.Message;
     }
 }
Beispiel #6
0
 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();
         }
     }
 }
Beispiel #7
0
 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();
         }
     }
 }
Beispiel #8
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);
                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();
                }
            }
        }