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!

有帮助吗?

解决方案

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" />
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top