asp.net 将大图压缩成小图片在首页上显示,为了加快显示速度

首页上显示图片,缩略图,图片在大图的基础上压缩成小图,然后在首页上显示

用C#生成缩略图,同时保存大图。好多这种代码网上
http://blog.csdn.net/zxmcl/article/details/1722770
http://blog.csdn.net/jinbiao520/article/details/8973774

给你一个思路:url重写
///
/// ResponseImg 的摘要说明
///
public class ResponseImg : IHttpHandler
{
static readonly DateTime Refresh;
static readonly DateTime Now;
static ResponseImg()
{
Now = DateTime.Now;
Refresh = Now.AddMonths(1);
}

    public void ProcessRequest(HttpContext context)
    {

        if (!string.IsNullOrEmpty(context.Request.Headers["If-Modified-Since"]))
        {
            DateTime IfModifiedSince = DateTime.Parse(context.Request.Headers["If-Modified-Since"]);
            if (IfModifiedSince > Now)
            {
                context.Response.StatusCode = 304;
                return;
            }
        }

        //string folder = context.Request.QueryString["Folder"];
        string filepath = context.Request.QueryString["FilePath"];
        int width = int.Parse(context.Request.QueryString["Width"]);
        int height = int.Parse(context.Request.QueryString["Height"]);
        string hex = context.Request.QueryString["Hex"];

        string path = context.Server.MapPath(string.Format("/QshopImg/{0}", filepath));

        byte[] bytes = ImageHelper.Reset(path, width, height);//这个是我写的图片压缩方法 你自己重新上网找
        //System.Drawing.Image img = ImageHelper.Reset(bytes, width, height);

        context.Response.Headers["Last-Modified"] = Refresh.ToString();
        //context.Response.Cache.SetExpires(DateTime.Now.Add(Refresh));
        //context.Response.Cache.SetMaxAge(refresh);
        context.Response.Cache.SetCacheability(HttpCacheability.Public);
        context.Response.CacheControl = HttpCacheability.Public.ToString();
        context.Response.Cache.SetValidUntilExpires(true);
        //context.Response.StatusCode = 304;
        //img.Save(context.Response.OutputStream, ImageHelper.GetImageFormat(path));
        context.Response.ContentType = "image/" + hex;

        context.Response.BinaryWrite(bytes);

    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}



        <rewrite url="~/(p_img\d{3}/.+?)_(\d{1,3})x(\d{1,3})\.(jpg|jpeg|png|gif|bmp)$"
         to="~/ResponseImg.ashx?FilePath=$1&amp;Width=$2&amp;Height=$3&amp;Hex=$4"/>

                    比如原图片的是/xxx/yyy.png
                    /xxx/yyy_64x64.png 
                    那么就会请求到ResponseImg.ashx 同时把原来的图片压缩成64*64 再输出

                    你还可以把压缩后的图片缓存起来,避免再次压缩

System.Drawing.Bitmap bmp = new Bitmap(文件目录);
bmp.GetThumbnailImage(宽度,高度,);