日期:2018-01-16  浏览次数:4604 次

 <img src="Handler.ashx?url=http://www.google.com.hk/intl/zh-CN/images/logo_cn.png" />
 
 
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Net;
using System.Drawing;
using System.IO;
 
public class Handler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        string imgUrl = context.Request["Url"];
        if (!string.IsNullOrEmpty(imgUrl))
        {
            Uri myUri = new Uri(imgUrl);
            WebRequest webRequest = WebRequest.Create(myUri);
            WebResponse webResponse = webRequest.GetResponse();
            Bitmap myImage = new Bitmap(webResponse.GetResponseStream());
 
            MemoryStream ms = new MemoryStream();
            myImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            context.Response.ClearContent();
            context.Response.ContentType = "image/Jpeg";
            context.Response.BinaryWrite(ms.ToArray());
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
}