Question

happy new year!

I just want to generate DataURL type data in VB.Net and also want to load string type DataURL to an image.

In other words, I want to convert an image in PictureBox(or Image) into string type DataURL vice versa.

The purpose of this kind of doubtful procedure is to save string data and image data into one single file.

Thank you!

Était-ce utile?

La solution

Something like this:

Use this function to get a Base64 string representation of the Image

Public Function ToBase64String(ByVal aImage As Image) As String
    Using stream = New System.IO.MemoryStream
        aImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
        Return Convert.ToBase64String(stream.ToArray)
    End Using
End Function

Then use this to display it:

<img src="data:image/png;base64, Base64StringHere" />
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top