如何在图像按钮上指定图像尺寸 [英] How to specify the Image sizes on Image buttons
本文介绍了如何在图像按钮上指定图像尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个中继器,里面有一个图像"按钮.
现在,来自数据库的图像具有不同的尺寸.
我想将所有图像调整为指定的尺寸,例如200x200.
1.如何做到这一点?
Hi,
I have a Repeater inside which I have an Image button.
Now,the images which are coming from the datebase are of varying dimensions.
I want to resize all the images to a specified dimension,200x200 say.
1.How to do that?
推荐答案
您应该简单地设置<asp:repeater xmlns:asp="#unknown"></asp:repeater>
中使用的<asp:imagebutton xmlns:asp="#unknown"></asp:imagebutton>
属性的Width和Height属性.这应该为图像按钮设置固定大小.
另外,您可以在CodeBehind中设置宽度"和高度",如下所示:
You should simply set Width and Height property of the<asp:imagebutton xmlns:asp="#unknown"></asp:imagebutton>
property that you are using inside the<asp:repeater xmlns:asp="#unknown"></asp:repeater>
. This should set a fixed size for the image buttons.
Alternatively, you can set the Width and Height in the CodeBehind as follows:
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
ImageButton imgBtn = e.Item.FindControl("Imge1") as ImageButton;
if (imgBtn != null)
{
imgBtn.Width = 200;
imgBtn.Height = 200;
}
}
}
但是,如果要调整从数据库中检索到的实际图像的大小,则需要使用.NET(GDI +)框架中提供的API调整其大小.不过,就性能而言,这将是昂贵的.
However, if you want to resize your actual image that you retrieve from the database, you need to resize it using the API available in .NET (GDI+) framework. That would be expensive in terms of performance though.
这篇关于如何在图像按钮上指定图像尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文