关于asp.net缩略图在Repeater显示急!!!

evanpatuo 2010-10-28 05:05:18
页面代码
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;
}


我需要很多张图片都是缩略图,结果只出现一张,页面其他内容都不见了右键查看源代码也查看不了!
请各位高手指点,是不是文件输出流有问题,该怎么弄,谢谢了!
...全文
239 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2010-10-28
  • 打赏
  • 举报
回复
等比例缩放图片
<script language="JavaScript">
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}

}
}
image.GetThumbnailImage
蝶恋花雨 2010-10-28
  • 打赏
  • 举报
回复
左下角有结贴或者右上角都有结贴按钮。
无爱大叔 2010-10-28
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 evanpatuo 的回复:]
好了是我粗心大意我把比例缩得太小了,在此谢谢楼上回帖的所有人,回帖的都有分可惜我分不多!最后一个回复教我怎么送分,结贴了!
[/Quote]
点结贴,找到xhbmj(鬼吹灯) 在后面的文本框里输入100,点确定
evanpatuo 2010-10-28
  • 打赏
  • 举报
回复
好了是我粗心大意我把比例缩得太小了,在此谢谢楼上回帖的所有人,回帖的都有分可惜我分不多!最后一个回复教我怎么送分,结贴了!
evanpatuo 2010-10-28
  • 打赏
  • 举报
回复
ROCK870210谢谢了,可以但是图片很模糊!有办法吗?
Rock870210 2010-10-28
  • 打赏
  • 举报
回复
<img style="vertical-align: middle; width:230px; height:260px;" src='GetImage.aspx?fn=<%# imgPath(Eval("SerialNumber")) %>' alt='<%# Eval("PName") %>' title="FERNANDO 120 PATENT LEATHER SANDALS" />
然后在GetImage页面

//获取路径自己写
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
Bitmap image = new Bitmap(ZoomBitmap(img,宽度,高度));
this.Response.ClearContent();
this.Response.ContentType = "image/Jpeg";
this.Response.CacheControl = "no-cache";
this.Response.Cache.SetNoStore();
this.Response.AddHeader("P3P", "CP=CAO PSA OUR");
image.Save(Response.OutputStream, ImageFormat.Jpeg);
image.Dispose();
img.Dispose();
img = null;
image = null;
evanpatuo 2010-10-28
  • 打赏
  • 举报
回复
Response.Redirect("GetThumbnail.aspx?fn=" + originalFileName); originalFileName=图片原来路径?
绑定这段代码是否需要变动
<img style="vertical-align: middle; width:230px; height:260px;" src='<%# imgPath(Eval("SerialNumber")) %>' alt='<%# Eval("PName") %>' title="FERNANDO 120 PATENT LEATHER SANDALS" />
不行
无爱大叔 2010-10-28
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 evanpatuo 的回复:]
引用 3 楼 rock870210 的回复:
把src指向一个单独aspx页面,该页面只接受一个参数,通过这个参数来找到图片,然后做成缩微图,用Response输出。
<IMG height=80 src='GetThumbnail.aspx?fn==<%# Server.UrlEncode(DataBinder.Eval("dd")/>这样吗?Response输出?我比较笨稍微详细些
[/Quote]
意思是<img style="vertical-align: middle; width:230px; height:260px;" src='GetThumbnail.aspx?fn=<%# Eval("SerialNumber") %>' alt='<%# Eval("PName") %>' title="FERNANDO 120 PATENT LEATHER SANDALS" />
生成缩略图由GetThumbnail.aspx页面来完成,fn传入图片的id,在GetThumbnail.aspx里得到原始图片的路径
string originalFileName = this.Server.MapPath("/WebUI/Image/ProductsImage/" + obj.ToString() + "/" + imgName);
然后转换成图片输出
evanpatuo 2010-10-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 rock870210 的回复:]
把src指向一个单独aspx页面,该页面只接受一个参数,通过这个参数来找到图片,然后做成缩微图,用Response输出。
[/Quote]<IMG height=80 src='GetThumbnail.aspx?fn==<%# Server.UrlEncode(DataBinder.Eval("dd")/>这样吗?Response输出?我比较笨稍微详细些
myhope88 2010-10-28
  • 打赏
  • 举报
回复
让它转向一个页面吧,通过一个专门的页面来处理图片
Rock870210 2010-10-28
  • 打赏
  • 举报
回复

/// <summary>
/// 缩放图片
/// </summary>
/// <param name="img">原图片</param>
/// <param name="iWidth">新的宽度</param>
/// <param name="iHeight">新的高度</param>
/// <returns></returns>
public static Image ZoomBitmap(Image img, int iWidth, int iHeight)
{
if (img == null) return new Bitmap(iWidth, iHeight);//返回空图像

Bitmap small = new Bitmap(iWidth, iHeight);
Graphics g = Graphics.FromImage(small);
g.SmoothingMode = SmoothingMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.Clear(Color.Transparent);
g.DrawImage(img, 0, 0, iWidth, iHeight);
return small;
}
无爱大叔 2010-10-28
  • 打赏
  • 举报
回复
在绑定的时候把图片弄成缩略图那效率也太低了。
在图片上传时就应该生成缩略图了,在绑定的时候调用就好了。

至于你的代码中实在无法看出什么,自己调试一下啊,看看生成的缩略图都在不在服务器端,还有返回的路径是否正确
Rock870210 2010-10-28
  • 打赏
  • 举报
回复
把src指向一个单独aspx页面,该页面只接受一个参数,通过这个参数来找到图片,然后做成缩微图,用Response输出。
evanpatuo 2010-10-28
  • 打赏
  • 举报
回复
自己顶!
evanpatuo 2010-10-28
  • 打赏
  • 举报
回复
是不是返回的路径还要做什么处理,

62,271

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧