求助关于Image img= new Image()

lc12d 2009-08-04 07:33:25
在后台new了一个img,然后给它赋地址,但是取出它的宽和高怎么无法使用啊。


Image img = new Image();
img.ImageUrl = "touxiang.aspx?table=sell_list&id=" + id;
if ( Convert.ToInt32(img.Width) > 0 && Convert.ToInt32(img.Height) > 0)


红色部分判断该怎么写呢,总说无法将类型为“System.Web.UI.WebControls.Unit”的对象强制转换为类型“System.IConvertible”。


不太理解其中的内涵
...全文
911 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
zouqi1981 2010-07-18
  • 打赏
  • 举报
回复
FromFile是不会为你解析aspx,生成Html流的.
重新根据参数到数据库中去读图片,
youyoubaihehua 2010-07-17
  • 打赏
  • 举报
回复
我也想知道答案
lc12d 2009-08-04
  • 打赏
  • 举报
回复
5楼和12楼的,我这样用了,可是出现错误。“touxiang.aspx?table=sell_list&id=45”不是有效的虚拟路径。 再说下,我的这个touxiang.aspx?table=sell_list&id=45是读数据库中二进制数据并返回的
libolei 2009-08-04
  • 打赏
  • 举报
回复
用 Bitmap 啦

好用
phf0313 2009-08-04
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 snowdust 的回复:]
C# code
System.Drawing.Image img= System.Drawing.Image.FromFile(Server.MapPath("touxiang.aspx?table=sell_list&id="+ id));if (Convert.ToInt32(img.Width)>0&& Convert.ToInt32(img.Height)>0)
{
}
[/Quote]
赞同.
SQL77 2009-08-04
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 lc12d 的回复:]
引用 10 楼 c0611010111 的回复:
img.Width属于System.Web.UI.WebControls.Unit
用img.Width > System.Web.UI.WebControls.Unit.Pixel(0)试试


这个属于想当然吧,肯定不行
[/Quote]
ImageList im = new ImageList();
im.Images.Add(Bitmap.FromFile(@"D:\My Documents\我的视频\richie\Angel\1a3fdbfd05a12f1c08244dd2.jpg"));
int width = im.Images[0].Width;
int height = im.Images[0].Height;
MessageBox.Show(width.ToString()+" "+height .ToString ());
lc12d 2009-08-04
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 c0611010111 的回复:]
img.Width属于System.Web.UI.WebControls.Unit
用img.Width > System.Web.UI.WebControls.Unit.Pixel(0)试试
[/Quote]

这个属于想当然吧,肯定不行
c0611010111 2009-08-04
  • 打赏
  • 举报
回复
img.Width属于System.Web.UI.WebControls.Unit
用img.Width > System.Web.UI.WebControls.Unit.Pixel(0)试试
lc12d 2009-08-04
  • 打赏
  • 举报
回复
哪位给出出主意啊,那个imagelist我更不知道怎么用了,MSDN上那么复杂,能给我哥实例吗,比如我这个该咋弄啊。
lc12d 2009-08-04
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 snowdust 的回复:]
C# code
System.Drawing.Image img= System.Drawing.Image.FromFile(Server.MapPath("touxiang.aspx?table=sell_list&id="+ id));if (Convert.ToInt32(img.Width)>0&& Convert.ToInt32(img.Height)>0)
{
}
[/Quote]

touxiang.aspx?table=sell_list&id="+id 是个页面从数据库中读出二进制数据流生成图片的,这样写,显示虚拟路径不正确啊。
wuyq11 2009-08-04
  • 打赏
  • 举报
回复
System.Drawing.Image image;
this.image = System.Drawing.Image.FromFile(imagePath);
SQL77 2009-08-04
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 lc12d 的回复:]
就是不懂啊,学习中呢,那该怎么处理呢



[/Quote]
用IMAGELIST呀
Snowdust 2009-08-04
  • 打赏
  • 举报
回复

System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("touxiang.aspx?table=sell_list&id=" + id));
if (Convert.ToInt32(img.Width) > 0 && Convert.ToInt32(img.Height) > 0)
{
}
lc12d 2009-08-04
  • 打赏
  • 举报
回复
就是不懂啊,学习中呢,那该怎么处理呢




SQL77 2009-08-04
  • 打赏
  • 举报
回复
ImageList I = new ImageList();
I.Images .Add();
int WIDTH = I.Images[0].Width;
IMAGE可以实例化???
这样
kennie_190602169 2009-08-04
  • 打赏
  • 举报
回复
Image img = new Image();

可以这样的? Image是抽象类啊!
lc12d 2009-08-04
  • 打赏
  • 举报
回复
直接写img.Width>0&& img.Height>0 也不对

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧