字节数组到图像转换
我想将字节数组转换为图像。
这是我获取字节数组的数据库代码:
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.
如何解决导致此异常的问题?
料青山看我应如是
明月笑刀无情
相关分类