B4A Library Base64 encode/decode image library

I noticed the other day that there were quite a few questions regarding decoding base64 image stings, so I quickly put together this simple but effective base64 encode/decode images library for others to use.

I will be turning more of my simple but useful routines to libraries, but not too many :)

Instructions:
In Globals add the following line
Dim Base64Con As Base64Image
Dim Base64Con As Base64Convert

To get an encoded base64 data stream, and return it as an bitmap ready to load into an image view for example, use the following line.
Base64Con.DecodeToImage(ImgStr As String) As Bitmap

Or

To get an image file, and encode it into an base64 data stream, ready to save into a database or file for example, use the following line.
Base64Con.EncodeFromImage(FolderPath As String, Filename As String) As String

Quite simple to use really.

Anyway, I hope that it work great for you all, well that's if anybody uses it :)
Just download the library and let me know what you think about it.

UPDATED: 09/04/2018: 1.10
Removed logs

This library is extremely simple to use.

SS_Base64Convert

Author: Peter Simpson
Version: 1.1
  • Base64Convert
    • Functions:
      • DecodeToImage (ImageStr As String) As Bitmap
        Use this call to decode the base64 datastream into an image
      • EncodeFromImage (FolderPath As String, Filename As String) As String
        Use this call to encode the image into a base64 datastream
      • Initialize As String
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.

Cheers :cool:
 

Attachments

  • Screenshot_2013-07-16-12-10-21.jpg
    Screenshot_2013-07-16-12-10-21.jpg
    27.9 KB · Views: 1,811
  • Base64Image.zip
    3 KB · Views: 1,638
Last edited:

Ganiadi

Active Member
Licensed User
Longtime User
hi, i tried to get image from other PC using VB and i could display the image again using the byte of array read from the image file, but when sent to b4a and it received the string completely, but when executing using Base64Con.DecodeToImage(cPackage) it raised error :

An error has occured in sub:main $ResumableSub_AStreams_NewDataResume(java line:722)
java.lang.NullPointerException:Attempt to invoke virtual method 'byte[] anywheresoftware.b4a.objects.StringUtils.DecodeBase64(java.lang.String)' on a null reference
Continue ?

Any advice, tks
 

marcos

Member
Licensed User
Longtime User
Thanks Erel, I thought as much..., so that explains it then.

1. When posting a string (using PostString) containing a query with a parameter that long (over 4000 characters), does it get truncated during the process or the entire string is sent?
2. Again, when the JobDone event fires, with the resulting query response after parsing the JSON (supposing I'm retrieving a string with over 4000 characters from a database), does it get truncated as well?


sorry for my english, did you solve it? I also have the same problem I printed the log on the txt file and it is correct, when I pass the data with poststring arrives cut to the service :-(. Someone can help me for days I can not understand the reason :-(
 

Carlos Muniz

Member
Licensed User
Longtime User
Hello Simpson:

Thanx for the library. Can you show me an example of converting a string into a picture and after saving it to an ImageView ?
( DecodeToImage (ImageStr As String) As Bitmap )
 
Top