C#读取二进制图片数据
byte[]bs=newbyte[2];while(reader.Read()){bs=(byte[])reader["Image"];}MemoryStreamms=n...
byte[] bs= new byte[2];
while (reader.Read())
{
bs= (byte[])reader["Image"];
}
MemoryStream ms = new MemoryStream(bs, true);
ms.Write(bs, 0, bs.Length);
pictureBox1.Image = new Bitmap(ms, true);
ms.Dispose();
conn.Close();
为什么我定义byte[?]?任意数字还是能显示图片?里面不是长度吗?不确定二进制图片数据多长,怎么定义?菜鸟呢^-^谢谢! 展开
while (reader.Read())
{
bs= (byte[])reader["Image"];
}
MemoryStream ms = new MemoryStream(bs, true);
ms.Write(bs, 0, bs.Length);
pictureBox1.Image = new Bitmap(ms, true);
ms.Dispose();
conn.Close();
为什么我定义byte[?]?任意数字还是能显示图片?里面不是长度吗?不确定二进制图片数据多长,怎么定义?菜鸟呢^-^谢谢! 展开
2个回答
展开全部
String sql = "select * from picture where [id]=2";
string str = "server=DA5A491B3F7544B;database=study;uid=sa;pwd=liyi123";
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand cmd=new SqlCommand(sql,con);
SqlDataReader sdr = cmd.ExecuteReader();
if(sdr.HasRows)
{
sdr.Read();
byte[] bytes = (byte[]) sdr["pic"];
MemoryStream ms =new MemoryStream(bytes);
Image image = Image.FromStream(ms);
pictureBox1.Image = image;
}
sdr.Close();
con.Close();
string str = "server=DA5A491B3F7544B;database=study;uid=sa;pwd=liyi123";
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand cmd=new SqlCommand(sql,con);
SqlDataReader sdr = cmd.ExecuteReader();
if(sdr.HasRows)
{
sdr.Read();
byte[] bytes = (byte[]) sdr["pic"];
MemoryStream ms =new MemoryStream(bytes);
Image image = Image.FromStream(ms);
pictureBox1.Image = image;
}
sdr.Close();
con.Close();
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询