关于asp.net缩略图在Repeater显示急!!!
页面代码
asp:Repeater ID="productsRpt" runat="server">
<ItemTemplate>
<li >
<div class="divcoents">
<div class="productWrap">
<div class="product" id="11647">
<div class="picture" hoverimage="">
<a href='/ChristianLouboutin/<%# Eval("Pid") %>'>
<img style="vertical-align: middle; width:230px; height:260px;" src='<%# imgPath(Eval("SerialNumber")) %>' alt='<%# Eval("PName") %>' title="FERNANDO 120 PATENT LEATHER SANDALS" />
这里绑定方法是返回图片的路径
</a>
</div>
</div>
</div>
</div>
<div class="clearboth" > </div>
</li>
</ItemTemplate>
</asp:Repeater>
后台代码是
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
//绑定商品图片
public string imgPath(object obj)
{
string imgName = "";
try
{
imgName = ProductsPictureManager.GetGoodsPictureBySerialNumber(obj.ToString()).PpPictureName;
}
catch (Exception e)
{
}
// this.Response.Clear();
string originalFileName = "";
try
{
originalFileName = this.Server.MapPath("/WebUI/Image/ProductsImage/" + obj.ToString() + "/" + imgName);
int thumbnailWidth = 100;
int thumbnailHeight = 100;
System.Drawing.Image img = System.Drawing.Image.FromFile(originalFileName);
ImageFormat thisFormat = img.RawFormat;
Size newSize = NewSize(thumbnailWidth, thumbnailHeight, img.Width, img.Height);
Bitmap outBmp = new Bitmap(thumbnailWidth, thumbnailHeight);
Graphics g = Graphics.FromImage(outBmp);
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.Clear(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(ImageFormat.Gif))
{
this.Response.ContentType = "image/gif";
}
else
{
this.Response.ContentType = "image/jpeg";
}
EncoderParameters encoderParams = new EncoderParameters();
long[] quality = new long[] { 100 };
EncoderParameter encoderParam = new EncoderParameter(Encoder.Quality, quality);
encoderParams.Param[0] = encoderParam;
ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo jpegICI = null;
int _Vb_t_i4_0 = arrayICI.Length - 1;
for (int fwd = 0; fwd <= _Vb_t_i4_0; fwd++)
{
if (arrayICI[fwd].FormatDescription.Equals("JPEG"))
{
jpegICI = arrayICI[fwd];
break;
}
}
if (jpegICI != null)
{
outBmp.Save(this.Response.OutputStream, jpegICI, encoderParams);
}
else
{
// '../lib/GetThumbnail.aspx?fn=<%# Server.UrlEncode(Configurationsettings.AppSettings("WareImgPath") & Container.DataItem("WareImgPath"))%>&tw=120&th=120'
outBmp.Save(this.Response.OutputStream, thisFormat);
}
img.Dispose();
outBmp.Dispose();
// this.lblImage.src = "";
}
catch (Exception exception1)
{
// ProjectData.SetProjectError(exception1);
Exception ex = exception1;
// ProjectData.ClearProjectError();
return originalFileName;
}
return originalFileName;
}
我需要很多张图片都是缩略图,结果只出现一张,页面其他内容都不见了右键查看源代码也查看不了!
请各位高手指点,是不是文件输出流有问题,该怎么弄,谢谢了!