我一直在想這個,但我沒有得到任何地方。我想要做的是這樣的:我有一個aspx頁面,您可以在其中上傳圖像(它們存儲在服務器上的文件夾中),在一個頁面上可以看到所有上傳的圖像,並生成鏈接(一個標籤)參考這些圖像,但直到現在它將全部圖像作爲「縮略圖」加載,並且它們的尺寸太大(1920x1200px),所以我用通用處理程序替換了圖像src,應該從圖像中獲取圖像文件夾,然後返回它,調整大小像說209x133px。如何從服務器文件夾中的圖像生成縮略圖?
但我不知道從哪裏開始,我會感激任何舉行,也許有人曾經做過類似的事情。
無論如何,感謝提前
這是我ceate的鏈接和圖像與中繼器:
protected void repImages_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item)
{
string sFile = e.Item.DataItem as string;
//Create the thumblink
HyperLink hlWhat = e.Item.FindControl("hlWhat") as HyperLink;
hlWhat.NavigateUrl = ResolveUrl("~/_img/_upload/" + sFile);
hlWhat.ToolTip = System.IO.Path.GetFileNameWithoutExtension(sFile);
hlWhat.Attributes["rel"] = "imagebox-bw";
hlWhat.Attributes["target"] = "_blank";
Image oImg = e.Item.FindControl("imgTheImage") as Image;
oImg.ImageUrl = ResolveUrl("Thumbnail.ashx?img=" + sFile);
oImg.Width = 203;
oImg.CssClass = "galleryImgs";
}
}
,現在來看,我的處理程序是這樣的:
<%@ WebHandler Language="C#" Class="Thumbnail" %>
using System;
using System.Web;
public class Thumbnail : IHttpHandler {
public void ProcessRequest (HttpContext context) {
if (!string.IsNullOrEmpty(context.Request.QueryString["img"]))
{
string fileName = context.Request.QueryString["img"];
}
else
{
}
}
public bool IsReusable {
get {
return false;
}
}
}
請參閱此問題http://stackoverflow.com/questions/2808887/create-thumbnail-image – Amitd
和這篇文章http://msdn.microsoft.com/en-us/library/system.drawing .image.getthumbnailimage.aspx – Amitd
選中此:http://www.dotnetspark.com/kb/1989-http-handlers-for-handling-images-on-fly.aspx – JurgenStillaert