Search code examples
androidimagebase64encode

Bitmap to String using Base64. How can fix it?


The Base64.encode doesn't want to take the argument "image", and I don't know how to figure out. I've never used Base64 before.

Bitmap bm = BitmapFactory.decodeStream(this.getContentResolver().openInputStream(uri));
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();  
                    bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object   
                    byte[] image = baos.toByteArray();

                    String encodedImage = Base64.encode(image);

Edit: I use an external package of Base64 http://iharder.sourceforge.net/current/java/base64/


Solution

  • Base64 encode takes at least two arguments. Perhaps try Base64.encode(image, Base64.DEFAULT)