我正在尝试制作一个简单的图片缩略图应用程序。我在网上搜索并找到了相当复杂的缩略图应用程序,以及简单的应用程序。我有一个很好的工作,如果我能让 ImageButton Resolution 看起来不错。目前,一切正常,但按钮的结果很糟糕(我尝试了各种宽度/高度变化)。
我只是遍历一组按钮图像并设置它们的属性。我调用 ThumbnailSize() 来设置 Imagebutton 的宽度/高度。
到目前为止,代码有点草率,但除此之外。我想知道是否有办法在拍照(800x600+/-)并将其缩小为 Imagebutton 时保持或增加 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;
}
}