title: Base64 Encoding takes too long time in Android
body: <p>I'm capturing an Image with the Camera. I save the File in the public photo directory and save the <code>Uri</code> to that file.</p>
  
  <p>I want to save the Image in a <code>Base64</code> <code>String</code> and put it on a <code>HashMap</code> to put it then in a XML file later.</p>
  
  <pre><code>protected Void doInBackground(Void...voids) {
          options.inJustDecodeBounds = false;
          //Bitmap bmp = BitmapFactory.decodeFile(imageFilePath,options);
          InputStream in = null;
          try {
              in = getContentResolver().openInputStream(Uri.parse(mCurrentPhotoPath));
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          }
          options.inSampleSize = 2;
          Bitmap image = BitmapFactory.decodeStream(in,null,options);
          int imgHeight = image.getHeight();
          int imgWidth = image.getWidth();
          while(imgHeight&gt;2000){
              imgHeight = imgHeight / 2;
          }
          while(imgWidth&gt;2000){
              imgWidth = imgWidth / 2;
          }
  
          Bitmap test = Bitmap.createScaledBitmap(image,imgWidth,imgHeight,false);
  
          String stest = base64EncodeDecode.encodeToBase64(test);
  
  
          items.put("image",base64EncodeDecode.encodeToBase64(test);
          return null;
  }
  </code></pre>
  
  <p>The <code>Base64</code> takes too long to encode it.
  <strong>encodeToBase64</strong> Method</p>
  
  <pre><code>public String encodeToBase64(Bitmap image) {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
      byte[] b = baos.toByteArray();
  
      return Base64.encodeToString(b, Base64.DEFAULT);
  }
  </code></pre>
  
  <p>Can you tell me if I do something wrong while encoding?</p>
  
  <p>I hope my problem is clear.</p>
  
  <p>Kind Regards!</p>