FREE VB.NET SOURCE CODE

24 April, 2012

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

I am sorry for the long delay, but here we go again !

A code to convert your bitmap/picturebox image to string and another one to reverse it.

But you must: Imports System.IO first ;)

 Public Function BitmapToString(ByVal bImage As Bitmap) As String
        Try
            Dim data As String
            Dim ms As MemoryStream = New MemoryStream
            bImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
            data = Convert.ToBase64String(ms.ToArray())

            Return data
        Catch ex As Exception
            Return String.Empty
        End Try
    End Function

Use it as this:


        Dim STR As String = BitmapToString(BITMAPIMAGE)

Or like this:

  Dim STR As String = BitmapToString(PictureBox1.Image)

The next post will be about a function, to convert it back to image/bitmap

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

No comments:

Post a Comment