0
votes

I want to convert my app images to base64 so it won't show on the gallery. I have tried various techniques. The image is from a zip file so it is a byte array at that point. The length of the base64 change when I change the byte array size. What is the proper byte array size? And the base64 encoded image doesn't work too. The primary code is String encodedImage = Base64.encodeToString(buffer, Base64.DEFAULT); buffer is the byte array(102400) and it contains the image too. The image is a 7KB file and the output is 400KB

1
You can use the Base64 Android class: String encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);Fady Saad
I included your answer in my question. And it doesn't work for me.Pixeldroid Modding
Wtong solution. If you want to prevent images from appearing in gallery, create a .nomedia file in that directory and the indexer will skip itGabe Sechan
It doesn't sound like the image fills the entire buffer...Louis Wasserman
Kindly answer your solution GabePixeldroid Modding

1 Answers

2
votes

You may try following function to convert image into Base64:

public void toStringImage(Bitmap bmp) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] imageBytes = baos.toByteArray();
    String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
}

Above function takes Bitmap image and converts it into Base64 encoded string. This is working in my project and I hope this will help you too.