示例#1
0
 public void ProcessRequest(HttpContext context)
 {
     System.Drawing.Image Cover;
     //判断请求的物理路径中,是否存在文件
     if (File.Exists(context.Request.PhysicalPath))
     {
         //加载文件
         Cover = Image.FromFile(context.Request.PhysicalPath);
         //加载水印图片
         Image watermark = Image.FromFile(context.Request.MapPath(WATERMARK_URL));
         //实例化画布
         Graphics g = Graphics.FromImage(Cover);
         //在image上绘制水印
         g.DrawImage(watermark, new Rectangle(Cover.Width - watermark.Width, Cover.Height - watermark.Height, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel);
         //释放画布
         g.Dispose();
         //释放水印图片
         watermark.Dispose();
     }
     else
     {
         //加载默认图片
         Cover = Image.FromFile(context.Request.MapPath(DEFAULTIMAGE_URL));
     }
     //设置输出格式
     context.Response.ContentType = "images/jpg";
     //将图片存入输出流
     Cover.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
     Cover.Dispose();
     context.Response.End();
 }
示例#2
0
 public void ProcessRequest(HttpContext context)
 {
     System.Drawing.Image Cover;
     //判断请求的物理路径,是否存在文件
     if (File.Exists(context.Request.PhysicalPath))
     {
         //加载文件
         Cover = System.Drawing.Image.FromFile(context.Request.PhysicalPath);
         //加载水印图片
         System.Drawing.Image watermark =
             System.Drawing.Image.FromFile(context.Request.MapPath(WATERMARK_URL));
         //实例化画布
         try
         {
             Graphics g = Graphics.FromImage(Cover);
             //在Cover上绘制水印
             //if (Cover.Width > 150 && Cover.Height > 180)
             //{
             // Cover.Width = 160;
             // Cover.Height = 177;
             //先第一次是原有图片的属性  第二次就是800 100 操控了第一次又不能左右 第二次的  。。
             //g.DrawImage(watermark, new Rectangle(Cover.Width - 1000,
             //   Cover.Height - 650, 1000, 650),
             // 0, 0, 1000, 650, GraphicsUnit.Pixel);
             //}
             //else
             //{
             g.DrawImage(watermark, new Rectangle(Cover.Width - watermark.Width,
                                                  Cover.Height - watermark.Height, watermark.Width, watermark.Height),
                         0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel);
             //}
             //释放画布
             g.Dispose();
             //释放水印图片
             watermark.Dispose();
         }catch (Exception ex)
         {
             ex.Message.ToString();
             Cover = System.Drawing.Image.FromFile(context.Request.MapPath(DEFAULTMARK_URL));
         }
     }
     else
     {
         //加载默认图片
         Cover = System.Drawing.Image.FromFile(context.Request.MapPath(DEFAULTMARK_URL));
     }
     //设置输出格式
     context.Response.ContentType = "image/jpeg";
     //将图片存入输出流
     Cover.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
     Cover.Dispose();
     context.Response.End();
 }
示例#3
0
        private const string DEFAULTIMAGE_URL = "~/Images/default.jpg";   //无图片时显示的图片
        public void ProcessRequest(HttpContext context)
        {
            string isbn = context.Request.QueryString["isbn"];
            //用户请求图片的url路径
            string imgUrl = "~/images/bookcovers/" + isbn + ".jpg";
            //用户请求图片的物理路径
            string filePath = context.Server.MapPath(imgUrl);
            Image  Cover;

            if (File.Exists(filePath))
            {
                //如果文件存在

                //加载封面文件
                Cover = Image.FromFile(filePath);

                //加载水印图片
                Image watermark = Image.FromFile(context.Server.MapPath(WATERMARK_URL));
                //实例化画布
                Graphics g = Graphics.FromImage(Cover);

                //new Rectangle(
                //在image上绘制水印

                g.DrawImage(watermark, new Rectangle(Cover.Width - watermark.Width, Cover.Height - watermark.Height, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel);
                //释放画布
                g.Dispose();
                //释放水印图片
                watermark.Dispose();
            }
            else
            {
                //封面图片不存在
                //加载默认图片
                Cover = Image.FromFile(context.Server.MapPath(DEFAULTIMAGE_URL));
            }
            //设置输出格式
            context.Response.ContentType = "image/jpeg";
            //将图片存入输出流
            Cover.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            Cover.Dispose();
            context.Response.End();
        }
        void ReleaseDesignerOutlets()
        {
            if (Cover != null)
            {
                Cover.Dispose();
                Cover = null;
            }

            if (PlaylistISongArtist != null)
            {
                PlaylistISongArtist.Dispose();
                PlaylistISongArtist = null;
            }

            if (PlaylistISongTitle != null)
            {
                PlaylistISongTitle.Dispose();
                PlaylistISongTitle = null;
            }
        }
        void ReleaseDesignerOutlets()
        {
            if (AddToQueueButton != null) {
                AddToQueueButton.Dispose ();
                AddToQueueButton = null;
            }

            if (Cover != null) {
                Cover.Dispose ();
                Cover = null;
            }

            if (FavouritesArtist != null) {
                FavouritesArtist.Dispose ();
                FavouritesArtist = null;
            }

            if (FavouritesTitle != null) {
                FavouritesTitle.Dispose ();
                FavouritesTitle = null;
            }
        }
示例#6
0
    public void ProcessRequest(HttpContext context)
    {
        Image Cover;

        //判断请求的物理路径中,是否存在该文件
        if (File.Exists(context.Request.PhysicalPath))
        {
            //加载文件
            Cover = Image.FromFile(context.Request.PhysicalPath);
            //加载水印图片
            Image watermark = Image.FromFile(context.Request.MapPath(WATERMARK_URL));
            //实例化画布
            Graphics     g     = Graphics.FromImage(Cover);
            StringFormat fmort = new StringFormat();
            fmort.Alignment     = StringAlignment.Center;
            fmort.LineAlignment = StringAlignment.Center;

            //Cover上绘制水印
            g.DrawImage(watermark, new Rectangle(Cover.Width - watermark.Width, Cover.Height - watermark.Height, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel);

            #region 文字水印

            //string logoText = "天府星空(http://www.tfxk.com) 版权所有 盗版必究";
            //float fontSize = 9; //字体大小
            //float textWidth = logoText.Length * fontSize; //文本的长度
            ////下面定义一个矩形区域,以后在这个矩形里画上白底黑字
            //float rectX = 0;
            //float rectY = Cover.Height - 18;
            //float rectWidth = Cover.Width;
            //float rectHeight = 18;
            ////声明矩形域
            //RectangleF textArea = new RectangleF(rectX, rectY, rectWidth, rectHeight);
            //Font font = new Font("宋体", fontSize); //定义字体
            //Brush whiteBrush = new SolidBrush(Color.White); //白笔刷,画文字用
            //Brush blackBrush = new SolidBrush(Color.FromArgb(207, 207, 207)); //黑笔刷,画背景用
            //g.FillRectangle(blackBrush, rectX, rectY, rectWidth, rectHeight);

            ////创建GDI+绘图图面
            //g.DrawString(logoText, font, whiteBrush, textArea, fmort);
            ////在背景图片上绘制水印文字
            //// g.DrawImage(Cover, new System.Drawing.Point(400, 300));

            #endregion

            //释放画布
            g.Dispose();
            //释放水印图片
            watermark.Dispose();
        }
        else
        {
            //加载默认图片
            Cover = Image.FromFile(context.Request.MapPath(DEFAULT_PIC));
        }
        //设置输出格式
        context.Response.ContentType = "image/jpeg";
        //将图片存入输出流
        Cover.Save(context.Response.OutputStream, ImageFormat.Jpeg);
        //释放资源
        Cover.Dispose();
        //停止HTTP响应
        context.Response.End();
    }