c#怎么把二进制数据转换为图片 5
stringad="疏楼龙宿";stringqry=@"SELECT头像FROM注册表WHERE用户名='"+ad+"'";adoa=newado();a.Connect...
string ad = "疏楼龙宿";
string qry= @" SELECT 头像 FROM 注册表 WHERE 用户名= '"+ad+"' ";
ado a = new ado();
a.Connect();
Page.Response.Write(a.myCon.State + "<br/>");
a.myCom = new SqlCommand(qry, a.myCon);
SqlDataReader dr = a.myCom.ExecuteReader();
if (dr.Read())
{
byte[] bytes = (byte[])dr["Image"];
FileStream fs = new FileStream(Server.MapPath("//view//1.gif"), FileMode.Create, FileAccess.Write);
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
fs.Close();
}
a.myCon.Close();
Image1.ImageUrl = "~/view/1.gif";
byte[] bytes = (byte[])dr["Image"]; 出错 这句话什么意思 那位前辈帮帮忙 展开
string qry= @" SELECT 头像 FROM 注册表 WHERE 用户名= '"+ad+"' ";
ado a = new ado();
a.Connect();
Page.Response.Write(a.myCon.State + "<br/>");
a.myCom = new SqlCommand(qry, a.myCon);
SqlDataReader dr = a.myCom.ExecuteReader();
if (dr.Read())
{
byte[] bytes = (byte[])dr["Image"];
FileStream fs = new FileStream(Server.MapPath("//view//1.gif"), FileMode.Create, FileAccess.Write);
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
fs.Close();
}
a.myCon.Close();
Image1.ImageUrl = "~/view/1.gif";
byte[] bytes = (byte[])dr["Image"]; 出错 这句话什么意思 那位前辈帮帮忙 展开
2个回答
展开全部
请确认你的Image列是什么数据类型!
参考下面的代码:
public void GetImage()
{
SqlCommand cmd = new SqlCommand(@"SELECT name, photo FROM Temp", sqlConn);
sqlConn.Open();
SqlDataReader reader = cmd .ExecuteReader();
if (reader.Read())
{
image_filename= (string) reader.GetValue(0);
byte[] image_bytes = (byte[]) reader.GetValue(1);
MemoryStream ms = new MemoryStream(image_bytes);
Bitmap bmap = new Bitmap(ms);
return bmap;
}
参考下面的代码:
public void GetImage()
{
SqlCommand cmd = new SqlCommand(@"SELECT name, photo FROM Temp", sqlConn);
sqlConn.Open();
SqlDataReader reader = cmd .ExecuteReader();
if (reader.Read())
{
image_filename= (string) reader.GetValue(0);
byte[] image_bytes = (byte[]) reader.GetValue(1);
MemoryStream ms = new MemoryStream(image_bytes);
Bitmap bmap = new Bitmap(ms);
return bmap;
}
追问
是image
展开全部
byte[] byte_img = Convert.FromBase64String(img64);
if (byte_img.Length > 10 * 1024 * 1000)
{
return ContentHelper.FailureInfo("图片大小超出限制");
}
MemoryStream s = new MemoryStream(byte_img);
Image image = Image.FromStream(s);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |