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!

Was it helpful?

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" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top