ShowImage.aspx显示页面DataList模板项html:
<ItemTemplate>
<asp:HyperLink id=HyperLink1 Target="_blank" NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.filename", "images/{0}") %>' Runat="server">
<asp:Image id=Image2 runat="server" ImageUrl='<%# "GetThumbnail.aspx?filename=" + Server.UrlEncode(DataBinder.Eval(Container, "DataItem.filename").ToString()) %>' AlternateText='<%# "文件名称:" + DataBinder.Eval(Container, "DataItem.filename") + "\n文件尺寸:" + DataBinder.Eval(Container, "DataItem.size") + " bytes" %>'>
</asp:Image>
</asp:HyperLink>
<asp:Button id="Button1" onclick="HHH" runat="server" Text="Button"></asp:Button>
</ItemTemplate>
图片处理页面GetThumbnail.aspx代码:
const int MaxLength=150; //显示图片最大长度
private void Page_Load(object sender, System.EventArgs e)
{
if (Request.QueryString["filename"] != null)
{
//取得原图
string filename=Request.QueryString["filename"];
Bitmap bmpOld= new Bitmap(Server.MapPath("images/" + filename));
//计算缩小比例
double d1;
if (bmpOld.Height>bmpOld.Width)
d1=(double)(MaxLength/(double)bmpOld.Height);
else
d1=(double)(MaxLength/(double)bmpOld.Width);
//产生缩图
Bitmap bmpThumb= new Bitmap(bmpOld,(int)(bmpOld.Width*d1),(int)(bmpOld.Height*d1));
// 清除缓冲
Response.Clear();
//生成图片
bmpThumb.Save(Response.OutputStream, ImageFormat.Jpeg);
Response.End();
//释放资源
bmpThumb.Dispose();
bmpOld.Dispose();
}
}