相册的简单实现
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
namespace TipsTricks.Ch4
{
/// <summary>
/// Summary description for ShowSmallImage.
/// </summary>
public class ShowSmallImage : System.Web.UI.Page
{
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.Width);
else
d1=(double)(MaxLength/(double)bmpOld.Height);
//产生缩图
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();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
namespace TipsTricks.Ch4
{
/// <summary>
/// Summary description for ShowSmallImage.
/// </summary>
public class ShowSmallImage : System.Web.UI.Page
{
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.Width);
else
d1=(double)(MaxLength/(double)bmpOld.Height);
//产生缩图
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();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
GetThumbnail.aspx
<%@ Page language="c#" Codebehind="ListImage.aspx.cs" AutoEventWireup="false" Inherits="TipsTricks.Ch4.ListImage" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ListImage</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="ListImage" method="post" runat="server">
<P><FONT face="黑体">
<asp:DataList id="DataList1" runat="server" Width="28px" RepeatColumns="2" RepeatDirection="Vertical"
BorderWidth="1px" GridLines="Vertical" CellPadding="3" BackColor="White" BorderStyle="None"
BorderColor="#999999">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
<HeaderTemplate>
<FONT face="宋体"></FONT>
</HeaderTemplate>
<SelectedItemTemplate>
<FONT face="宋体"></FONT>
</SelectedItemTemplate>
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle ForeColor="Black" BackColor="#EEEEEE"></ItemStyle>
<ItemTemplate>
<asp:HyperLink id=HyperLink1 Runat="server" NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.filename", "images/{0}") %>' Target="_blank">
<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>
</asp:DataList></P>
</form>
</FONT>
</body>
</HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ListImage</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="ListImage" method="post" runat="server">
<P><FONT face="黑体">
<asp:DataList id="DataList1" runat="server" Width="28px" RepeatColumns="2" RepeatDirection="Vertical"
BorderWidth="1px" GridLines="Vertical" CellPadding="3" BackColor="White" BorderStyle="None"
BorderColor="#999999">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
<HeaderTemplate>
<FONT face="宋体"></FONT>
</HeaderTemplate>
<SelectedItemTemplate>
<FONT face="宋体"></FONT>
</SelectedItemTemplate>
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle ForeColor="Black" BackColor="#EEEEEE"></ItemStyle>
<ItemTemplate>
<asp:HyperLink id=HyperLink1 Runat="server" NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.filename", "images/{0}") %>' Target="_blank">
<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>
</asp:DataList></P>
</form>
</FONT>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
namespace TipsTricks.Ch4
{
/// <summary>
/// Summary description for ListImage.
/// </summary>
public class ListImage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataList DataList1;
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
//获取文件名称
string[] files=Directory.GetFiles(Server.MapPath("images"));
//建立数据表
DataTable dt=new DataTable();
dt.Columns.Add("filename");
dt.Columns.Add("size");
foreach (string s in files)
{
DataRow dr=dt.NewRow();
FileInfo f=new FileInfo(s);
dr["filename"]=f.Name;
dr["size"]=f.Length;
dt.Rows.Add(dr);
}
//绑定显示
this.DataList1.DataSource=dt;
this.DataList1.DataBind();
}
}
public void HHH(object sender, System.EventArgs e)
{
this.Response.Write("hello");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
namespace TipsTricks.Ch4
{
/// <summary>
/// Summary description for ListImage.
/// </summary>
public class ListImage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataList DataList1;
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
//获取文件名称
string[] files=Directory.GetFiles(Server.MapPath("images"));
//建立数据表
DataTable dt=new DataTable();
dt.Columns.Add("filename");
dt.Columns.Add("size");
foreach (string s in files)
{
DataRow dr=dt.NewRow();
FileInfo f=new FileInfo(s);
dr["filename"]=f.Name;
dr["size"]=f.Length;
dt.Rows.Add(dr);
}
//绑定显示
this.DataList1.DataSource=dt;
this.DataList1.DataBind();
}
}
public void HHH(object sender, System.EventArgs e)
{
this.Response.Write("hello");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}