Create Intent to crop Image - Android android.graphics

Android examples for android.graphics:Image Operation

Description

Create Intent to crop Image

Demo Code

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;

public class Main {

  static String TAG = "";

  public static boolean cropImage(Uri picUri, int requsetCode, Activity activity) {
    try {//w w w  . j ava2  s  .  c  o  m

      Intent cropIntent = new Intent("com.android.camera.action.CROP");
      cropIntent.setDataAndType(picUri, "image/*");
      cropIntent.putExtra("crop", "true");
      // cropIntent.putExtra("aspectX", 1);
      // cropIntent.putExtra("aspectY", 1);
      cropIntent.putExtra("outputX", 200);
      cropIntent.putExtra("outputY", 200);
      cropIntent.putExtra("scale", true);
      cropIntent.putExtra("return-data", true);
      cropIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());

      activity.startActivityForResult(cropIntent, requsetCode);
      return true;
    } catch (ActivityNotFoundException anfe) {
      return false;
    }
  }

}

Related Tutorials