I was creating a sample app for uploading images to server and i found on the stackoverflow about compressing and encoding the image to base64 before uploading.
My Code:
public String encodeTobase64(Bitmap image)
{
System.gc(); //For memory efficiency
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String imageEncoded = null;
imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);
return imageEncoded;
}
The main problem that has arisen is that when i try to encode a small size image around 2-3 kb it encodes it in a flash and provides me the encoded string in a textview (just for checking if encoding or not)...but when i try to encode a image of large size like more than 1 mb , the app hangs and after 5 minutes it provides the answer and until this duration app is unaccesible.
Even though i have created a new thread for this encoded method the encoding is not fast enough ...
So i wanted to know if there was any other way of encoding more efficiently and fast or if i could make this method more efficient and fast