的高度和宽度,我必须为服务器端图像控制:如何计算图像
<img id="img" runat="server" style="padding-left:20px"
src="~/Images/2013-02-14_225913.png" />
我要计算其高度和宽度。我这样做:
int iWidth = (int)Math.Round((decimal)img.Width.Value);
int iHeight = (int)Math.Round((decimal)img.Height.Value);
这将返回-0,而不是实际参数。
如何获得图像控制的H & W?
如果你的'img'是'Image'类的,只是'img.Height'应该给你的像素高度整数。 – 2013-02-15 09:26:31
你想获得控件的大小或图片的真实大小吗? – 2013-02-15 09:40:41
作为一个说法,'img'对象不具有'.Value'属性,因为它在服务器端被实例化为'System.Web.UI.HtmlControls.HtmlImage'。如果您使用' ',那么该类将具有'System.Web.UI.WebControls.Image',它具有'.Value'属性。 –
2013-02-15 09:48:01