我正在嘗試製作一個簡單的圖片縮略圖應用程序。我搜索了網絡,發現了相當複雜的縮略圖應用程序,簡單的應用程序。我有一個很好的工作,如果我能得到ImageButton決議看起來不錯。目前,一切工作正常,但按鈕的resoultion是可怕的(我試過各種寬度/高度變化)。C#ImageButton圖片分辨率
我只是遍歷按鈕圖像的數組並設置它們的屬性。我調用ThumbnailSize()來設置Imagebutton的寬度/高度。
現在的代碼有點草率,但除此之外就是這樣。我想知道是否有一種方法可以在拍攝圖片時保持或增加ImageButton分辨率(800x600 +/-)並將其縮小爲Imagebutton。
string[] files = null;
files = Directory.GetFiles(Server.MapPath("Pictures"), "*.jpg");
ImageButton[] arrIbs = new ImageButton[files.Length];
for (int i = 0; i < files.Length; i++)
{
arrIbs[i] = new ImageButton();
arrIbs[i].ID = "imgbtn" + Convert.ToString(i);
arrIbs[i].ImageUrl = "~/Gallery/Pictures/pic" + i.ToString() + ".jpg";
ThumbNailSize(ref arrIbs[i]);
//arrIbs[i].BorderStyle = BorderStyle.Inset;
arrIbs[i].AlternateText = System.IO.Path.GetFileName(Convert.ToString(files[i]));
arrIbs[i].PostBackUrl = "default.aspx?img=" + "pic" + i.ToString();
pnlThumbs.Controls.Add(arrIbs[i]);
}
}
public ImageButton ThumbNailSize(ref ImageButton imgBtn)
{
//Create Image with ImageButton path, and determine image size
System.Drawing.Image img =
System.Drawing.Image.FromFile(Server.MapPath(imgBtn.ImageUrl));
if (img.Height > img.Width)
{
//Direction is Verticle
imgBtn.Height = 140;
imgBtn.Width = 90;
return imgBtn;
}
else
{
//Direction is Horizontal
imgBtn.Height = 110;
imgBtn.Width = 130;
return imgBtn;
}
}
http://stackoverflow.com/questions/249587/high-quality-image-scaling-c – 2009-11-21 08:04:12