Пример #1
0
 protected void Page_Load(object sender, System.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 = Globals.ApplicationPath + text;
             pIC.SendSmallImage(base.Request.MapPath(text), maxHeight, maxWidth);
             string watermarkFilename            = base.Request.MapPath(Globals.ApplicationPath + "/Admin/images/watermark.gif");
             System.IO.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 (System.Exception ex)
     {
         this.label_html = ex.Message;
     }
 }
Пример #2
0
        public void SendSmallImage(string fileName, int maxHeight, int maxWidth)
        {
            Image image = null;

            this._outBmp = null;
            Graphics graphics = null;

            try
            {
                image = Image.FromFile(fileName);
                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);

                if (graphics != null)
                {
                    graphics.Dispose();
                }
            }
            catch
            {
            }
            finally
            {
                if (graphics != null)
                {
                    graphics.Dispose();
                }
                if (image != null)
                {
                    image.Dispose();
                }
            }
        }
Пример #3
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 encoderParameters = new EncoderParameters();
                long[]            value             = new long[]
                {
                    100L
                };

                EncoderParameter encoderParameter = new EncoderParameter(Encoder.Quality, value);
                encoderParameters.Param[0] = encoderParameter;
                ImageCodecInfo[] imageEncoders  = ImageCodecInfo.GetImageEncoders();
                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();
                }
            }
        }