I have a stored procedure that return a varbinary(max) type data. I want to convert that data into an Image.
But I have problems with this line:
public Image CargarAvatar(string login)
{
System.Object[] Args = new System.Object[1];
Args[0] = login;
DataTable X = new DataTable();
X = TraerDataTable("sp_CargarAvatarUsuario", Args);
byte[] ImagemByte = Convert.to (X.Rows[0][0].ToString());
MemoryStream ms = new MemoryStream();
Image returnImage = Image.FromStream(ms);
return returnImage;
}
Please help! :D
A varbinary field is returned as a byte array, so you only need to cast it:
byte[] ImagemByte = (byte[])X.Rows[0][0];
Then you use the array to create the memory stream:
MemoryStream ms = new MemoryStream(ImagemByte);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With