title: Cropping Image in Android (Crop Intent)
body: <p>I used this <a href="http://www.androidhub4you.com/2012/07/how-to-crop-image-from-camera-and.html" rel="nofollow">code</a> to use android's built in image crop tools. My code is the following</p>
  
  <pre><code> public void takePicture(){
      Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      if (takePictureIntent.resolveActivity(getPackageManager()) != null){
          takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString());
          takePictureIntent.putExtra("crop", "true");
          takePictureIntent.putExtra("aspectX", 0);
          takePictureIntent.putExtra("aspectY", 0);
          takePictureIntent.putExtra("outputX", 200);
          takePictureIntent.putExtra("outputY", 150);
          takePictureIntent.putExtra("return-data", true);
  
          startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
      }
  
  }
  
  protected void onActivityResult(int requestCode, int resultCode, Intent data){
      if (requestCode == REQUEST_IMAGE_CAPTURE &amp;&amp; resultCode == RESULT_OK) {
          Bundle extras = data.getExtras();
          Bitmap imageBitmap = (Bitmap) extras.get("data");
          imageViewImage.setImageBitmap(imageBitmap);
  
      }
  }
  </code></pre>
  
  <p>takePicture is called inside a click listener for a Button. What is done is I can open android camera take the picture and when hitting save the image is saved on my imageView. But no cropping activity appears, plus the image on imageView looks awfull. The quality is like it's pixelated. Am I doing something wrong? I used a Samsung galaxy tab 3 to test my app</p>
  
  <p>EDIT using the answer bellow...Stil not working</p>
  
  <pre><code> protected void onActivityResult(int requestCode, int resultCode, Intent data){
      if (requestCode == REQUEST_IMAGE_CAPTURE &amp;&amp; resultCode == RESULT_OK) {
          Bundle extras = data.getExtras();
          Log.d("onActivityResult", "Inside on activity for result");
          Bitmap imageBitmap = (Bitmap) extras.get("data");
          imageViewImage.setImageBitmap(imageBitmap);
          fileUri = getImageUri(this, imageBitmap);χ
          cropImage();
      }else if (requestCode == REQUEST_IMAGE_CROP &amp;&amp; resultCode == RESULT_OK){
          Bundle extras = data.getExtras();
          Bitmap imageBitmap = (Bitmap)extras.get("data");
          imageViewImage.setImageBitmap(imageBitmap);
  
  
      }
  }
  
   public void takePicture(){
      Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      if (takePictureIntent.resolveActivity(getPackageManager()) != null){
  
          startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
      }
  
  }
  
   public void cropImage() {
      try {
  
          Intent cropIntent = new Intent("com.android.camera.action.CROP");
  
          cropIntent.setDataAndType(fileUri, "image/*");
          cropIntent.putExtra("crop", "true");
          cropIntent.putExtra("aspectX", 1);
          cropIntent.putExtra("aspectY", 1);
          cropIntent.putExtra("outputX", 128);
          cropIntent.putExtra("outputY", 128);
          cropIntent.putExtra("return-data", true);
          startActivityForResult(cropIntent, REQUEST_IMAGE_CROP);
      }
      // respond to users whose devices do not support the crop action
      catch (ActivityNotFoundException anfe) {
          // display an error message
          String errorMessage = "Whoops - your device doesn't support the crop action!";
          Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
          toast.show();
      }
  }
  public Uri getImageUri(Context inContext, Bitmap inImage) {
      ByteArrayOutputStream bytes = new ByteArrayOutputStream();
      inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
      String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
      return Uri.parse(path);
  }
  </code></pre>
  
  <p><a href="http://pastebin.com/Wt43zvnk" rel="nofollow">LocCat here</a></p>