相册的简单实现

None.gifusing System;
None.gif
using System.Collections;
None.gif
using System.ComponentModel;
None.gif
using System.Data;
None.gif
using System.Data.SqlClient;
None.gif
using System.Drawing;
None.gif
using System.Drawing.Imaging;
None.gif
using System.Web;
None.gif
using System.Web.SessionState;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.HtmlControls;
None.gif
using System.IO;
None.gif
None.gif
namespace TipsTricks.Ch4
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Summary description for ShowSmallImage.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class ShowSmallImage : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
const int MaxLength=150;  //最大长度
InBlock.gif

InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (Request.QueryString["filename"!= null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//取得原图
InBlock.gif
                string filename=Request.QueryString["filename"];
InBlock.gif                Bitmap bmpOld
= new Bitmap(Server.MapPath("images/" + filename)); 
InBlock.gif
InBlock.gif                
//计算缩小比例
InBlock.gif
                double d1;
InBlock.gif                
if (bmpOld.Height>bmpOld.Width)
InBlock.gif                    d1
=(double)(MaxLength/(double)bmpOld.Width);
InBlock.gif                
else
InBlock.gif                    d1
=(double)(MaxLength/(double)bmpOld.Height);
InBlock.gif
InBlock.gif                
//产生缩图
InBlock.gif
                Bitmap bmpThumb= new Bitmap(bmpOld,(int)(bmpOld.Width*d1),(int)(bmpOld.Height*d1));
InBlock.gif
InBlock.gif                
// 清除缓冲 
InBlock.gif
                Response.Clear();
InBlock.gif                
//生成图片
InBlock.gif
                bmpThumb.Save(Response.OutputStream, ImageFormat.Jpeg);
InBlock.gif                Response.End();
InBlock.gif                
//释放资源
InBlock.gif
                bmpThumb.Dispose();
InBlock.gif                bmpOld.Dispose();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Web Form Designer generated code#region Web Form Designer generated code
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Required method for Designer support - do not modify
InBlock.gif        
/// the contents of this method with the code editor.
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
存为  
 GetThumbnail.aspx


ExpandedBlockStart.gifContractedBlock.gif<%dot.gif@ Page language="c#" Codebehind="ListImage.aspx.cs" AutoEventWireup="false" Inherits="TipsTricks.Ch4.ListImage" %>
None.gif
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
None.gif
<HTML>
None.gif    
<HEAD>
None.gif        
<title>ListImage</title>
None.gif        
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
None.gif        
<meta name="CODE_LANGUAGE" Content="C#">
None.gif        
<meta name="vs_defaultClientScript" content="JavaScript">
None.gif        
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
None.gif    
</HEAD>
None.gif    
<body MS_POSITIONING="FlowLayout">
None.gif        
<form id="ListImage" method="post" runat="server">
None.gif            
<P><FONT face="黑体">
None.gif                    
<asp:DataList id="DataList1" runat="server" Width="28px" RepeatColumns="2" RepeatDirection="Vertical"
None.gif                        BorderWidth
="1px" GridLines="Vertical" CellPadding="3" BackColor="White" BorderStyle="None"
None.gif                        BorderColor
="#999999">
None.gif                        
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
None.gif                        
<HeaderTemplate>
None.gif                            
<FONT face="宋体"></FONT>
None.gif                        
</HeaderTemplate>
None.gif                        
<SelectedItemTemplate>
None.gif                            
<FONT face="宋体"></FONT>
None.gif                        
</SelectedItemTemplate>
None.gif                        
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
None.gif                        
<ItemStyle ForeColor="Black" BackColor="#EEEEEE"></ItemStyle>
None.gif                        
<ItemTemplate>
None.gif                            
<asp:HyperLink id=HyperLink1 Runat="server" NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.filename", "images/{0}") %>' Target="_blank">
ExpandedBlockStart.gifContractedBlock.gif                                
<asp:Image id=Image2 runat="server" ImageUrl='<%# "GetThumbnail.aspx?filename=" + Server.UrlEncode(DataBinder.Eval(Container, "DataItem.filename").ToString()) %>' AlternateText='<%dot.gif"文件名称:" + DataBinder.Eval(Container, "DataItem.filename"+ "\n文件尺寸:" + DataBinder.Eval(Container, "DataItem.size"+ " bytes" %>'>
None.gif                                
</asp:Image>
None.gif                            
</asp:HyperLink>
None.gif                            
<asp:Button id="Button1" onclick="HHH" runat="server" Text="Button"></asp:Button>
None.gif                        
</ItemTemplate>
None.gif                    
</asp:DataList></P>
None.gif        
</form>
None.gif        
</FONT>
None.gif    
</body>
None.gif
</HTML>
None.gif


None.gifusing System;
None.gif
using System.Collections;
None.gif
using System.ComponentModel;
None.gif
using System.Data;
None.gif
using System.Drawing;
None.gif
using System.Web;
None.gif
using System.Web.SessionState;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.HtmlControls;
None.gif
using System.IO;
None.gif
None.gif
namespace TipsTricks.Ch4
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Summary description for ListImage.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class ListImage : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected System.Web.UI.WebControls.DataList DataList1;
InBlock.gif    
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (!IsPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//获取文件名称
InBlock.gif
                string[] files=Directory.GetFiles(Server.MapPath("images"));
InBlock.gif                
//建立数据表
InBlock.gif
                DataTable dt=new DataTable();
InBlock.gif                dt.Columns.Add(
"filename");
InBlock.gif                dt.Columns.Add(
"size");
InBlock.gif
InBlock.gif                
foreach (string s in files)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    DataRow dr
=dt.NewRow();
InBlock.gif                    FileInfo f
=new FileInfo(s);
InBlock.gif                    dr[
"filename"]=f.Name;
InBlock.gif                    dr[
"size"]=f.Length;
InBlock.gif                    dt.Rows.Add(dr);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
//绑定显示
InBlock.gif
                this.DataList1.DataSource=dt;
InBlock.gif                
this.DataList1.DataBind();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void HHH(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Response.Write("hello");
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
Web Form Designer generated code#region Web Form Designer generated code
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Required method for Designer support - do not modify
InBlock.gif        
/// the contents of this method with the code editor.
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
以上为调用页面...

转载于:https://www.cnblogs.com/gwazy/archive/2005/05/12/153650.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值