title: Take picture and convert to Base64
body: <p>I use code below to make a picture with camera. Instead of saving I would like to encode it to <code>Base64</code> and after that pass it to another API as an input. I can't see method, how to modify code to take pictures in <code>Base64</code> instead of regular files.</p>
  
  <pre><code>public class CameraDemoActivity extends Activity {
      int TAKE_PHOTO_CODE = 0;
      public static int count = 0;
  
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/picFolder/";
          File newdir = new File(dir);
          newdir.mkdirs();
  
          Button capture = (Button) findViewById(R.id.btnCapture);
          capture.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  count++;
                  String file = dir+count+".jpg";
                  File newfile = new File(file);
                  try {
                      newfile.createNewFile();
                  }
                  catch (IOException e)
                  {
                  }
  
                  Uri outputFileUri = Uri.fromFile(newfile);
  
                  Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                  cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
  
                  startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
              }
          });
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
  
          if (requestCode == TAKE_PHOTO_CODE &amp;&amp; resultCode == RESULT_OK) {
              Log.d("CameraDemo", "Pic saved");
          }
      }
  }
  </code></pre>
  
  <p>I try to use code below to convert an image to <code>Base64</code>.</p>
  
  <pre><code>public static String encodeToBase64(Bitmap image, Bitmap.CompressFormat compressFormat, int quality)
  {
      ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
      image.compress(compressFormat, quality, byteArrayOS);
      return Base64.encodeToString(byteArrayOS.toByteArray(), Base64.DEFAULT);
  }
  </code></pre>
  
  <p>Above described should be a much more direct and easier way than saving image and after that looking for image to encode it.</p>