c# - C# 字节 array 到图像转换

  显示原文与译文双语对照的内容
120 4

我想将字节 array 转换为图像。

这是我从那里获取字节 array的数据库代码:

public void Get_Finger_print()
{
 try
 {
 using (SqlConnection thisConnection = new SqlConnection(@"Data Source=" + System.Environment.MachineName +"\SQLEXPRESS;Initial Catalog=Image_Scanning;Integrated Security=SSPI"))
 {
 thisConnection.Open();
 string query ="select pic from Image_tbl";//where Name='" + name +"'";
 SqlCommand cmd = new SqlCommand(query, thisConnection);
 byte[] image =(byte[]) cmd.ExecuteScalar();
 Image newImage = byteArrayToImage(image);
 Picture.Image = newImage;
//return image;
 }
 }
 catch (Exception) { }
//return null;
}

我的转换代码:

public Image byteArrayToImage(byte[] byteArrayIn)
{
 try
 {
 MemoryStream ms = new MemoryStream(byteArrayIn,0,byteArrayIn.Length);
 ms.Write(byteArrayIn, 0, byteArrayIn.Length);
 returnImage = Image.FromStream(ms,true);//Exception occurs here
 }
 catch { }
 return returnImage;
}

当我使用注释到达行时,出现以下异常:Parameter is not valid.

如何修复导致这里异常的任何内容?

时间:原作者:0个回答

...