【发布时间】:2012-08-19 07:23:15
【问题描述】:
我想限制 asp.net C# 图像的尺寸。
我有 image1:
ImageButton ib = (ImageButton)sender;
Image1.ImageUrl = ib.ImageUrl;
我也有:
Image tempImage = new Image();
tempImage.ImageUrl = ib.ImageUrl;
接下来我正在设置 image1 的尺寸
Image1.Width = Math.Max(tempImage.Width, 1000);
在这里我得到编译器错误:math.max 有错误的参数。 所以目标是不允许图像的宽度大于 1000。 如何做到这一点?
【问题讨论】:
-
您是否查看过 MSDN 的 Math.Max 方法,您是否想过更安全的方法 Math.Min ...?确保您还为两个参数传递相同的数据类型
-
我也尝试比较两个宽度 if(tempImage.Width > tempImage2.Width),这里编译器错误也给出了一个错误,说 tempImage.Width 方法返回 System.Web.UI.WebControls.Unit
-
您能否显示发生方法和错误的完整代码..
-
Image1.Width = Math.Max(tempImage.Width, 1000);
-
您已经得到答案:“tempImage.Width 方法返回 System.Web.UI.WebControls.Unit”。在 MSDN 上查找:msdn.microsoft.com/en-us/library/… 并发现您需要使用
Value属性来获取double值。
标签: c# asp.net image restriction image-size