字節(jié)數(shù)組到圖像轉(zhuǎn)換我想將字節(jié)數(shù)組轉(zhuǎn)換為圖像。這是我獲取字節(jié)數(shù)組的數(shù)據(jù)庫(kù)代碼: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;}我的轉(zhuǎn)換代碼: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;}當(dāng)我通過(guò)注釋到達(dá)該行時(shí),會(huì)發(fā)生以下異常: Parameter is not valid.如何解決導(dǎo)致此異常的問(wèn)題?
3 回答

料青山看我應(yīng)如是
TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超8個(gè)贊
也許我錯(cuò)過(guò)了一些東西,但對(duì)我來(lái)說(shuō),這個(gè)單行程序可以正常工作,其中包含一個(gè)包含JPEG文件圖像的字節(jié)數(shù)組。
Image x = (Bitmap)((new ImageConverter()).ConvertFrom(jpegByteArray));
編輯:
請(qǐng)參閱此處獲取此答案的更新版本:如何在字節(jié)數(shù)組中轉(zhuǎn)換圖像

明月笑刀無(wú)情
TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超4個(gè)贊
public Image byteArrayToImage(byte[] bytesArr) { using (MemoryStream memstr = new MemoryStream(bytesArr)) { Image img = Image.FromStream(memstr); return img; } }
- 3 回答
- 0 關(guān)注
- 434 瀏覽
添加回答
舉報(bào)
0/150
提交
取消