I have a varbinary(max) field in Microsoft SQL Server which contains an image.
When running "SELECT IMAGE FROM TABLE", I get a result which looks like "0x07FD30...."
When using go to retrieve the data, I get the same hex string which is stored as a []byte:
type Person struct {
PersonID string
Image []byte
}
I connect to the database and do:
rows.Scan(&person.PersonID, &person.Image)
And then print the result as hex, it's the same:
fmt.Printf("%#x", p.Image)
Result:
0x07fd30...
My question is, how do I turn this back into an image?
I've tried writing the raw bytes to a file:
ioutil.WriteFile("./tempfile.png", p.Image, 0644)
I've tried using the image library to decode it, which just errors with an unidentified kind:
image.Decode(bytes.NewReader(p.Image))
And also tried png.Encode
too.
Any thoughts or pointers in the right direction greatly appreciated.
Many thanks in advance.