title: Terrible performance getting image from camera with intent
body: <p>I'm using the <code>ACTION_IMAGE_CAPTURE</code> intent to allow users of my app to take a photo. I then get that photo and save it so that I can display it in an <code>ImageView</code> in the app. </p>
  
  <p>The code works but the performance is awful. Once the user takes a picture the camera app lets them confirm by pressing a checkmark. Once this is pressed the screen stays for a few seconds then goes black for 5-8 seconds before eventually returning to my app.</p>
  
  <p>As I said the code works, it's just incredibly slow. Any ideas on how I can improve it of where the bottleneck is?</p>
  
  <pre><code>public void onImageViewClicked (View v) {
      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile(this)) ); 
      startActivityForResult(intent, 1);
  }
  
  private File getTempFile(Context context){
      final File path = new File( Environment.getExternalStorageDirectory(), context.getPackageName() );
      if(!path.exists()){
         path.mkdir();
      }
      return new File(path, "image.tmp");
  }
  
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (resultCode == RESULT_OK) {
          switch(requestCode){
            case 1:
              final File file = getTempFile(this);
              try {
                Bitmap captureBmp = Media.getBitmap(getContentResolver(), Uri.fromFile(file) );
              ImageView imageView = (ImageView) this.findViewById(R.id.myImageView);
              imageView.setImageBitmap(captureBmp);
              savePicture("before", captureBmp, getApplicationContext());
            imageView.setBackgroundColor(getResources().getColor(android.R.color.black));
  
              } catch (FileNotFoundException e) {
                e.printStackTrace();
              } catch (IOException e) {
                e.printStackTrace();
              }
            break;
         }
      }
  }
  
  private void savePicture(String filename, Bitmap b, Context ctx){
      try {
          ObjectOutputStream oos;
          FileOutputStream out;
          out = ctx.openFileOutput(filename, Context.MODE_PRIVATE);
          oos = new ObjectOutputStream(out);
          b.compress(Bitmap.CompressFormat.PNG, 100, oos);
  
          oos.close();
          oos.notifyAll();
          out.notifyAll();
          out.close();
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  
  private Bitmap loadPicture(String filename, Bitmap b){
  
      try {
          FileInputStream fis = openFileInput(filename);
          ObjectInputStream ois = null;
          try {
              ois = new ObjectInputStream(fis);
          } catch (StreamCorruptedException e1) {
              e1.printStackTrace();
          } catch (IOException e1) {
              e1.printStackTrace();
          }
  
          b = BitmapFactory.decodeStream(ois);
          try {
              ois.close();
              fis.close();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
      } catch (FileNotFoundException e) {
          e.printStackTrace();
      }
  
      ImageView imageView = (ImageView) this.findViewById(R.id.myImageView);
      imageView.setImageBitmap(b);
    if (b == null) {
      imageView.setBackgroundColor(getResources().getColor(android.R.color.transparent));
    }
      return b;
  
  }
  </code></pre>