FREE VB.NET SOURCE CODE

24 April, 2012

[SNP] Convert Base64 string to BItmap / Image / Picturebox.Image [VB.NET]

Okay, this is the second part of :
[SNP] Convert Image / PictureBox Image / Bitmap to string / text [VB.NET]


Here is a function, that will convert the Base64 string to Bitmap / Image back again.

But first:

Imports System.IO

Then:

 Public Function StringToBitmap(ByVal sImageData As String) As Bitmap
        Try
            Dim ms As New MemoryStream(Convert.FromBase64String(sImageData))
            Dim bmp As Bitmap = Bitmap.FromStream(ms)
            Return bmp
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

Use it like this:

 Dim IMG As Bitmap = StringToBitmap("PUT CONVERTED IMAGE'S STRING HERE")

Or like this:

   PictureBox1.Image = StringToBitmap("PUT CONVERTED IMAGE'S STRING HERE")

Do not forget, that if you put the image's string in a textbox, it may limit the default lenght of the textbox.text.


[SNP] Convert Image / PictureBox Image / Bitmap to string / text [VB.NET]

No comments:

Post a Comment