0

I'm loading a picture from my phone then I'm encoding it using base64 encoding just like this :

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);

As I was wondering about this string I'm getting, I displayed it like this :

new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    final AlertDialog builder = new AlertDialog.Builder(DataActivity.this).create();
                    builder.setTitle("Title");
                    builder.setMessage(encodedImage);
                    builder.show();
                }
            },2500);

I'm getting a decent string with all the letters and numbers with + and / and ==. So it's "working". However when I use a website to encode it, I'm getting a totally different string. Here is a part of the beginning of the string on my phone : http://img11.hostingpics.net/pics/136937Screenshot20150212023946.png and the website where I encoded my picture : http://www.base64-image.de/step-2.php. The beginning of the string is (according to the website) :

iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT

Am I missing something? . Thank you

AshBringer
  • 2,614
  • 2
  • 20
  • 42
  • There are different variants of [Base64](http://en.wikipedia.org/wiki/Base64). What your phone is doing is probably a different variant than what that website is doing. – Jesper Feb 12 '15 at 19:00
  • It doesn't matter. If you're making a Base64 in your code and it's fine then use it. [Just paste the string you are getting here](http://www.askapache.com/online-tools/base64-image-converter/) and check if it is making the same image you used. If it is being made, don't care about it. – Tushar Gogna Feb 12 '15 at 19:00
  • 2
    you are compressing the image `bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);` after having opened it. It is 2 different files – njzk2 Feb 12 '15 at 19:04
  • Thanks for the replies! I forgot about the compress, must be that. Thanks again – AshBringer Feb 12 '15 at 19:09

0 Answers0