How to retrieve images from sql server?

  • Thread starter Thread starter Luis Esteban Valencia
  • Start date Start date
How to retrieve images from sql server?

Luis

Convert the image to text to save it in the database:

<code>
Public Overloads Shared Function ToString(ByVal image As
System.Drawing.Image) As String
Dim ms As New IO.MemoryStream
image.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
Return System.Convert.ToBase64String(ms.GetBuffer)
End Function

Public Shared Function FromString(ByVal imageString As String) As
System.Drawing.Image
Dim imageBytes() As Byte =
System.Convert.FromBase64String(imageString)
Dim ms As New IO.MemoryStream(imageBytes)
FromString = System.Drawing.Image.FromStream(ms)
ms.Close()
End Function
</code>

Hope this helps

Blu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top