[求助]关于页面缩略图不能显示的问题??
下面的这段代码是缩略图的实现:getThunbnail.aspx:
private void Page_Load(object sender, System.EventArgs e)
{
//获取几个参数,用以生成缩略图片
//设置一个默认参数生成BitMap
Response.Clear();
try
{
string originalFileName=Server.MapPath(Request["fn"]);
int thumbnailWidth=Convert.ToInt32(Request["tw"].ToString());
int thumbnailHeight=Convert.ToInt32(Request["th"].ToString());
System.Drawing.Image img=System.Drawing.Image.FromFile(originalFileName);
System.Drawing.Imaging.ImageFormat thisFormat=img.RawFormat;
System.Drawing.Size newSize=this.GetNewSize(thumbnailWidth,thumbnailHeight,img.Width,img.Height);
System.Drawing.Bitmap outBmp=new System.Drawing.Bitmap(thumbnailWidth,thumbnailHeight);
System.Drawing.Graphics g=System.Drawing.Graphics.FromImage(outBmp);
//设置画布的描绘质量
g.CompositingQuality=System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.Clear(System.Drawing.Color.FromArgb(0xff,0xf9,0xff,240));
Rectangle _Vb_t_record_0 = new Rectangle((int) Math.Round((double) (((double) (thumbnailWidth - newSize.Width)) / 2)), (int) Math.Round((double) (((double) (thumbnailHeight - newSize.Height)) / 2)), newSize.Width, newSize.Height);
g.DrawImage(img, _Vb_t_record_0, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
g.Dispose();
if(thisFormat.Equals(System.Drawing.Imaging.ImageFormat.Gif))
{
Response.ContentType="image/gif";
}
else
{
Response.ContentType="image/jpeg";
}
//设置压缩质量
System.Drawing.Imaging.EncoderParameters encoderParams=new System.Drawing.Imaging.EncoderParameters();
long[] quality=new long[] {100};
System.Drawing.Imaging.EncoderParameter encoderParam=new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality,quality);
encoderParams.Param[0]=encoderParam;
//获得包含有关内置图像编码解码器的信息的ImageCodecInfo 对象。
System.Drawing.Imaging.ImageCodecInfo[] arrayICI=System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders();
System.Drawing.Imaging.ImageCodecInfo jpegICI=null;
int length = arrayICI.Length - 1;
for(int fwd=0;fwd<=length;fwd++)
{
if(arrayICI[fwd].FormatDescription.Equals("JPEG"))
{
jpegICI=arrayICI[fwd];
break;
}
}
if(jpegICI!=null)
{
outBmp.Save(Response.OutputStream,jpegICI,encoderParams);
}
else
{
outBmp.Save(Response.OutputStream,thisFormat);
}
}
catch(Exception ex)
{
return;
}
// 在此处放置用户代码以初始化页面
}
public System.Drawing.Size GetNewSize(int maxWidth,int maxHeight,int width,int height)
{
double w=0.0;
double h=0.0;
double sw=Convert.ToDouble(width);
double sh=Convert.ToDouble(height);
double mw=Convert.ToDouble(maxWidth);
double mh=Convert.ToDouble(maxHeight);
if(sw<mw && sh<mh)
{
w=sw;
h=sh;
}
else
{
if((sw/sh)>(mw/mh))
{
w=maxWidth;
h=(w*sh)/sw;
}
else
{
h=maxHeight;
w=(h*sw)/sh;
}
}
return new System.Drawing.Size(Convert.ToInt32(w),Convert.ToInt32(h));
}
我想要在这个页面引用上面的实现方法
<%@ Register TagPrefix="uc1" TagName="register" Src="GloabalUserControls/register.ascx" %>
<%@ Register TagPrefix="uc1" TagName="footer" Src="GloabalUserControls/footer.ascx" %>
<%@ Register TagPrefix="uc1" TagName="header" Src="GloabalUserControls/header.ascx" %>
<%@ Page language="c#" Codebehind="szll.aspx.cs" AutoEventWireup="false" Inherits="jswljx.szll" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>szll</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="myCss/GLOBAL.CSS" type="text/css" rel="stylesheet">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<TABLE id="Table1" cellSpacing="1" cellPadding="0" width="768" align="center" border="0">
<TR>
<TD align="center" colSpan="2"><uc1:header id="Header1" runat="server"></uc1:header></TD>
</TR>
<tr>
<td align="center" colSpan="2">
<TABLE id="Table4" borderColor="#99ccff" cellSpacing="0" cellPadding="0" width="100%" align="center"
border="1">
<TR>
<TD align="right"><asp:textbox id="txtSearch" runat="server"></asp:textbox><asp:button id="btnSearch" runat="server" Text="搜 索"></asp:button> </TD>
</TR>
</TABLE>
</td>
</tr>
<TR>
<TD style="WIDTH: 234px" width="234"><uc1:register id="Register1" runat="server"></uc1:register></TD>
<TD><asp:datalist id="dlTeacher" runat="server" RepeatDirection="Horizontal" RepeatColumns="3">
<ItemTemplate>
<TABLE id="Table2" style="WIDTH: 129px; HEIGHT: 129px" cellSpacing="1" cellPadding="1"
width="129" align="center" border="0">
<TR>
<TD vAlign="middle" align="center"><A title='<%# DataBinder.Eval(Container.DataItem,"teaName")%>' href='<%#"showTeacherDetails.aspx?teaID="+DataBinder.Eval(Container.DataItem,"teaID")%>' target=_blank>
<asp:Image id="Image1" runat="server" Width="128px" Height="128px" ImageUrl='<%# DataBinder.Eval(Container.DataItem,"photoPath")%>'>
</asp:Image></A></TD>
</TR>
<TR>
<TD align="center"><A title='<%# DataBinder.Eval(Container.DataItem,"teaName")%>' href='<%#"showTeacherDetails.aspx?teaID="+DataBinder.Eval(Container.DataItem,"teaID")%>' target=_blank><%#GetSub(DataBinder.Eval(Container.DataItem,"teaName"),10)%>
<asp:Label id="lblTeaname" runat="server"></asp:Label></A></TD>
</TR>
</TABLE>
</ItemTemplate>
</asp:datalist></TD>
</TR>
<tr>
<td align="center" colSpan="2">
<TABLE id="Table3" borderColor="#99ccff" cellSpacing="0" cellPadding="1" width="100%" align="center"
border="1">
<TR>
<TD align="right">共<asp:label id="lblRecordCount" runat="server"></asp:label>条记录 共<asp:label id="lblPageCount" runat="server"></asp:label>页 第<asp:label id="lblCurrentPage" runat="server"></asp:label>页
<asp:linkbutton id="lbtnFirst" runat="server">首页</asp:linkbutton>
<asp:linkbutton id="lbnPrevPage" runat="server">上一页</asp:linkbutton>
<asp:linkbutton id="lbnNextPage" runat="server">下一页</asp:linkbutton>
<asp:linkbutton id="lbtnLast" runat="server">末页</asp:linkbutton>
<asp:dropdownlist id="ddlPage" runat="server" AutoPostBack="True" Width="46px"></asp:dropdownlist> </TD>
</TR>
</TABLE>
</td>
</tr>
<TR>
<TD align="center" colSpan="2"><uc1:footer id="Footer1" runat="server"></uc1:footer></TD>
</TR>
</TABLE>
</FONT>
</form>
</body>
</HTML>
我按照网上的说法好像不行,请高手给与指点,在这里我先说声谢谢了!
[此贴子已经被作者于2007-4-26 21:18:01编辑过]