How to retrieve images from sql server?

Discussion in 'ASP .Net' started by Luis Esteban Valencia, Oct 22, 2004.

  1. How to retrieve images from sql server?
     
    Luis Esteban Valencia, Oct 22, 2004
    #1
    1. Advertisements

  2. Luis Esteban Valencia

    BluDog Guest

    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
     
    BluDog, Oct 22, 2004
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.