日期:2014-05-20  浏览次数:20699 次

如何获取从数据库中读取出的图片尺寸
数据库:SQL   Server   2005
语言:C#
数据类型:image
如何获取图片的width   &   height??


------解决方案--------------------
只要你能把图片数据读出来还原成图片用Image属性就知道Height,Width了
------解决方案--------------------
在存储的时候就把这两个存到数据库中。
------解决方案--------------------
1. if (Convert.IsDBNull(o))
{
hasPhoto = false;
}
else
{
ks_photo = (byte[])dt.Tables[0].Rows[0][ "ks_photo "];
if (ks_photo.Length == 0)
hasPhoto = false;
else
hasPhoto = true;
}
2. public static Image Photo
{
get
{
if (hasPhoto == false)
return null;
System.IO.MemoryStream ms = new System.IO.MemoryStream(ks_photo);
Image im = Image.FromStream(ms);
ms.Close();
return im;
}
}
3.Photo.Width,Photo.Height