I managed to convert an Image to a varbinary and store it in my database. I have been trying to convert the varbinary to an Image but I’m running in some trouble here.
First I get the Binary from my database in my service.
public Binary getAfbeelding(int id)
{
var query = (from p in dc.Afbeeldings
where p.id == id
select p.source).Single();
Binary source = query;
return source;
}
Then I try to convert the varbinary to an image, using code found on StackOverflow:
public static string convertToImage(Binary source)
{
byte[] b = source.ToArray();
MemoryStream ms = new MemoryStream(b);
Image img = Image.FromStream(ms);
return img.Source.ToString();
}
I am running into trouble before the call to new MemoryStream :
‘OndernemersAward.EditAfbeeldingServiceReference.Binary’ does not contain a definition for ‘ToArray’ and no extension method ‘ToArray’ accepting a first argument of type
‘OndernemersAward.EditAfbeeldingServiceReference.Binary’ could be found (are you missing a using directive or an assembly reference?)
For some weird reason, I CANNOT use the ‘normal’ Binary, it will ALWAYS tell me to use OndernemersAward.EditAfbeeldingServiceReference.Binary which is my ServiceReference, as you can see.
How can this be solved?
1) Add reference into your project to System.Data.Linq.dll
2) And then try this: