मैं एक बाइट सरणी को एक छवि में परिवर्तित करना चाहता हूं।बाइट ऐरे छवि रूपांतरण
जहाँ मैं बाइट सरणी मिल से मेरी डेटाबेस कोड यह है:
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.
इस अपवाद को उत्पन्न करने वाले किसी भी चीज़ को मैं कैसे ठीक कर सकता हूं?
क्या आपने जांच की है कि आपकी क्वेरी में छवि बाइट मान्य हैं? आप सत्यापित करने के लिए एक फ़ाइल.WriteAllBytes ("myimage.jpg", byteArrayIn) कर सकते हैं। – Holstebroe