img src="Handler.ashx?PhotoID=&Size=S"

很奇怪的事情,只是发现了,但不明白为什么!
ContractedBlock.gif ExpandedBlockStart.gif Handler
 1None.gif<%@ WebHandler Language="C#" Class="Handler" %>
 2None.gif
 3None.gifusing System;
 4None.gifusing System.IO;
 5None.gifusing System.Web;
 6None.gif
 7ExpandedBlockStart.gifContractedBlock.gifpublic class Handler : IHttpHandler dot.gif{
 8InBlock.gif
 9ExpandedSubBlockStart.gifContractedSubBlock.gif    public bool IsReusable dot.gif{
10ExpandedSubBlockStart.gifContractedSubBlock.gif        get dot.gif{
11InBlock.gif            return true;
12ExpandedSubBlockEnd.gif        }

13ExpandedSubBlockEnd.gif    }

14InBlock.gif    
15ExpandedSubBlockStart.gifContractedSubBlock.gif    public void ProcessRequest (HttpContext context) dot.gif{
16InBlock.gif        // Set up the response settings
17InBlock.gif        context.Response.ContentType = "image/jpeg";
18InBlock.gif        context.Response.Cache.SetCacheability(HttpCacheability.Public);
19InBlock.gif        context.Response.BufferOutput = false;
20InBlock.gif        // Setup the Size Parameter
21InBlock.gif        PhotoSize size;
22ExpandedSubBlockStart.gifContractedSubBlock.gif        switch (context.Request.QueryString["Size"]) dot.gif{
23InBlock.gif            case "S":
24InBlock.gif                size = PhotoSize.Small;
25InBlock.gif                break;
26InBlock.gif            case "M":
27InBlock.gif                size = PhotoSize.Medium;
28InBlock.gif                break;
29InBlock.gif            case "L":
30InBlock.gif                size = PhotoSize.Large;
31InBlock.gif                break;
32InBlock.gif            default:
33InBlock.gif                size = PhotoSize.Original;
34InBlock.gif                break;
35ExpandedSubBlockEnd.gif        }
 
36InBlock.gif        // Setup the PhotoID Parameter
37InBlock.gif        Int32 id = -1;
38InBlock.gif        Stream stream = null;
39ExpandedSubBlockStart.gifContractedSubBlock.gif        if (context.Request.QueryString["PhotoID"!= null && context.Request.QueryString["PhotoID"!= ""dot.gif{
40InBlock.gif            id = Convert.ToInt32(context.Request.QueryString["PhotoID"]);
41InBlock.gif            stream = PhotoManager.GetPhoto(id, size);
42ExpandedSubBlockStart.gifContractedSubBlock.gif        }
 else dot.gif{
43InBlock.gif            id = Convert.ToInt32(context.Request.QueryString["AlbumID"]);
44InBlock.gif            stream = PhotoManager.GetFirstPhoto(id, size);
45ExpandedSubBlockEnd.gif        }

46InBlock.gif        // Get the photo from the database, if nothing is returned, get the default "placeholder" photo
47InBlock.gif        if (stream == null) stream = PhotoManager.GetPhoto(size);
48InBlock.gif        // Write image stream to the response stream
49InBlock.gif        const int buffersize = 1024 * 16;
50InBlock.gif        byte[] buffer = new byte[buffersize];
51InBlock.gif        int count = stream.Read(buffer, 0, buffersize);
52ExpandedSubBlockStart.gifContractedSubBlock.gif        while (count > 0dot.gif{
53InBlock.gif            context.Response.OutputStream.Write(buffer, 0, count);
54InBlock.gif            count = stream.Read(buffer, 0, buffersize);
55ExpandedSubBlockEnd.gif        }

56ExpandedSubBlockEnd.gif    }

57InBlock.gif
58ExpandedBlockEnd.gif}
据说是能以流的方式直接读取存在数据库中的图片。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值