0

I have an image that I encode using this code :

Bitmap bm = BitmapFactory.decodeFile(selectedImagePath);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
            byte[] b = baos.toByteArray();
            encodedImage = Base64.encodeToString(b, Base64.DEFAULT);

It encodes well. After that I'm getting the String in a file in my computer and I try to decode it with this website : http://www.askapache.com/online-tools/base64-image-converter/ And I'm getting a null picture. However, when I decode it directly in my app and display it like :

public static Bitmap decodeBase64(String input) {
    byte[] decodedByte = Base64.decode(input, 0);
    return BitmapFactory
            .decodeByteArray(decodedByte, 0, decodedByte.length);
}

private ImageView img;
img.setImageBitmap(decodeBase64(encodedImage));

I'm getting the right picture. So I was wondering if i actually can't decode an android encoded image with an other decoder than android's one or my file is corrupted meaning that I have missing characters. However even if I don't have the whole encoded file, the decoded picture i'm getting with the website should look like to the good one right ? Thank you in advance

AshBringer
  • 2,614
  • 2
  • 20
  • 42
  • Did you try to let the website encode the jpg (not the bitmap)? Compare both base64 strings. What's the difference? – greenapps Feb 13 '15 at 16:55
  • `even if I don't have the whole encoded file, the decoded picture i'm getting with the website should look like to the good one right`. Of course not. You should encode the whole jpg and give the website the complete base64 text. – greenapps Feb 13 '15 at 16:57
  • I have this compression operation bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); So the string in Android and the string of the website won't be same – AshBringer Feb 13 '15 at 16:58
  • I mean when you open a picture with notepad++ for instance and you delete some characters, you get a pic that looks like to the original with some different pixels. Isn't what I'm supposed to have here ? – AshBringer Feb 13 '15 at 17:10
  • Let your android app save it to file as .jpg first. Then take that file and let both encode it. Then compare the base64 texts. Don't mess around with bitmaps and so. Just encode a file. – greenapps Feb 13 '15 at 18:47

0 Answers0