用c#将二进制转换成图片
公司里有一个项目,以前都存二进制进sql的,现在需要把它分离出来保存到一个文件夹,请问应该怎么做呢,有没相关实例? --------------------编程问答--------------------
byte[] byteimage=new byte[0];
byteimage=(byte[]) dr[0];//SqlDataReader
MemoryStream stream=new MemoryStream(byteimage);
image im=Image.FromStream(stream);
--------------------编程问答--------------------
byte[] data=GetDataFromSql();//从数据库得到2进制的数据
MemoryStream stream = new MemoryStream(data);
Image image=Image.FromStream(stream); --------------------编程问答-------------------- byte[] bytes = 数据库字段信息;
FileStream fs = new FileStream(文件名, FileMode.Create, FileAccess.Write);
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
fs.Close(); --------------------编程问答--------------------
--------------------编程问答-------------------- 马上试看看,谢谢大家。
SqlConnection cn = new SqlConnection(你的链接字符);
SqlDataReader dr = null;
SqlCommand cm = new SqlCommand();
cm.Connection = cn;
cm.CommandType = CommandType.Text;
cm.CommandText = "sql语句";
cn.Open();
dr = cm.ExecuteReader();
byte[] File = null;
if (dr.Read())
{
File = (byte[])dr[0];
}
cn.Close();
FileStream fs;
FileInfo fi = new System.IO.FileInfo(@"c:\myfile.txt");
fs = fi.OpenWrite();
Image image=Image.FromStream(fs);
fs.Close();
补充:.NET技术 , C#