ASP.Net之瞒天过海

 

None.gifusing System;
None.gif
using
 System.Web;
None.gif
using
 System.Drawing;
None.gif
using
 System.Drawing.Imaging;
None.gif
using
 System.Net;
None.gif
using
 System.IO;
None.gif
None.gif
namespace
 Goodspeed.test.httphandle
ExpandedBlockStart.gifContractedBlock.gif
dot.gif
{
InBlock.gif
InBlock.gif    
public class
 myjpg : IHttpHandler
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif
{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public myjpg() dot.gif{ }

InBlock.gif
InBlock.gif        
public void ProcessRequest(HttpContext Context)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
{
InBlock.gif            HttpResponse Response 
=
 Context.Response;
InBlock.gif            HttpRequest Request 
=
 Context.Request;
InBlock.gif            
string Url =
 Request.Url.ToString();
InBlock.gif            
//Url = "http://www.allinone.net.cn/office/photo/pic/20040714/" + Url.Substring(Url.LastIndexOf("/") + 1);

InBlock.gif
            Url = "http://img1.qq.com/news/20040721/490452.jpg";
InBlock.gif
InBlock.gif            Response.ContentType 
= "image/JPEG"
;
InBlock.gif
InBlock.gif            WebClient wc 
= new
 WebClient();
InBlock.gif            Stream resStream 
=
 wc.OpenRead(Url);
InBlock.gif            Image originalimage 
= Image.FromStream(resStream);//获取图像

InBlock.gif

ContractedSubBlock.gifExpandedSubBlockStart.gif            
方法二#region 方法二
InBlock.gif            
//byte[] myDataBuffer = wc.DownloadData(Url);            
InBlock.gif            
//Response.BinaryWrite(myDataBuffer);

ExpandedSubBlockEnd.gif
            #endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
水印#region 水印
InBlock.gif            Image newImage 
= Image.FromFile("c:\watermark1.gif");
InBlock.gif            
//水印

InBlock.gif
            using (Graphics g = Graphics.FromImage(originalimage))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
{
InBlock.gif                Point ulCorner 
= new Point(originalimage.Width - newImage.Width - 5, originalimage.Height - newImage.Height - 5);//水印的位置

InBlock.gif
                g.DrawImage(newImage, ulCorner);
InBlock.gif                g.Dispose();
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
InBlock.gif            originalimage.Save(Response.OutputStream, ImageFormat.Jpeg);
InBlock.gif            Response.End();
InBlock.gif            originalimage.Dispose();
InBlock.gif            wc.Dispose();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public bool IsReusable
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn true; }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值