Reputation: 51
My database is SQL Server. In that one photo data column is there. That is varbinary
datatype. How to retrieve the original image from that code. Please suggest any better way
Regards, Pradeep
Upvotes: 0
Views: 732
Reputation: 23113
VarBinary is binary - so cast the field in the resultset to byte[]
byte[] bytes = (byte[])dataReader["fieldname"];
Then use a MemoryStream
to convert the bytes to Image
public Image BytesToImage(byte[] bytes)
{
using(MemoryStream ms = new MemoryStream(bytes))
{
Image image = Image.FromStream(ms);
return image;
}
}
Upvotes: 1