我正在尝试制作一个简单的图片缩略图应用程序。我搜索了网络,发现了相当复杂的缩略图应用程序,简单的应用程序。我有一个很好的工作,如果我能得到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