B4A Library [B4X] Library Base64 encode/decode image library

MarcoRome

Expert
Licensed User
From an idea of the Great Peter ( https://www.b4x.com/android/forum/threads/base64-encode-decode-image-library.31031/ ) "...in attached the library for decoding base64 image stings, so I quickly put together this simple but effective base64 encode/decode images library for others to use..."

The library is for B4X (Tested with B4J, B4A, B4i)

The Example Code:

B4X:
'File 653 kb
    File.Copy(File.DirAssets, "653.jpg", File.DirInternal,"653.jpg")
    Sleep(300)

    'Image to Encode64
    Dim base As String = Base64EncodeDecodeImage.Base64ImageToString(File.DirInternal,"653.jpg")
      
    'Check if Valid Base64
    If Base64EncodeDecodeImage.ValidBase64(base) Then
        ImageView1.Bitmap = Base64EncodeDecodeImage.Base64StringToImage(base)
    End If
Example Code B4A --> https://www.dropbox.com/s/mohtg21cnfvaj1p/CONVERTBMPTOCODE64B4.zip?dl=0
Example Code B4i --> https://www.dropbox.com/s/97x5hcexy9xgkm6/CONVERTBMPTOCODE64.zip?dl=0
Example Code B4J -->https://www.dropbox.com/s/888ic5l1m18f4d1/B4J-CONVERTBMPTOCODE64.zip?dl=0

In attachment library b4xlib
Have a nice day
Marco
 

Attachments

Last edited:

LucaMs

Expert
Licensed User
Very useful, Marco, thank you.

Since I wanted a second method to "import" a bitmap in your Base64ImageToString, which reads an image file
(I "needed" to pass it a B4XBitmap), I added it but I also took the opportunity to change something.
If you "like" my changes you can add this version to your first post and I will remove this one ;)

Description of changes:
B4X:
' Base64EcondeDecodeImage - Code module
' Author:    MarcoRome

#Region VERSIONS
' 1.1
'    Added ImageToString method, which is identical to Base64ImageToString,
'        but its name is more "correct". Kept Base64ImageToString for backward compatibility.
'    Added ImageToString2 method, which requires a B4XBitmap parameter.
'    Renamed variable name "convert" to mStringUtils
'        and declared it as Private in Process_Globals.
'    Added B4XBitmapToBytes private method - used by ImageToString2.
'    Added some Regions.
' 1.0
#End Region
 

Attachments

Last edited:
Top