crop Image Intent - Android android.graphics

Android examples for android.graphics:Image Operation

Description

crop Image Intent

Demo Code

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

public class Main {
  public static final int REQUEST_CODE_TAKE_PHOTO = 0xF1;
  public static final int REQUEST_CODE_CROP = REQUEST_CODE_TAKE_PHOTO + 5;

  public static void cropImage(Uri uri, int width, int height, Activity activity) {
    Intent intent = cropImageIntent(uri, width, height);
    activity.startActivityForResult(intent, REQUEST_CODE_CROP);
  }/*from  www.  j  a  va2 s  . c  o  m*/

  public static void cropImage(Uri uri, int width, int height, android.support.v4.app.Fragment fragment) {
    Intent intent = cropImageIntent(uri, width, height);
    fragment.startActivityForResult(intent, REQUEST_CODE_CROP);
  }

  private static Intent cropImageIntent(Uri uri, Uri outputUri, int width, int height) {
    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uri, "image/*");
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);
    // intent.putExtra("data", data);
    intent.putExtra("crop", "true");

    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);

    intent.putExtra("outputX", width);
    intent.putExtra("outputY", height);
    intent.putExtra("return-data", false);
    intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());

    intent.putExtra("noFaceDetection", true);
    return intent;
  }

  private static Intent cropImageIntent(Uri uri, int width, int height) {
    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uri, "image/*");
    intent.putExtra("crop", "true");

    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);

    intent.putExtra("outputX", width);
    intent.putExtra("outputY", height);
    intent.putExtra("return-data", true);
    intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());

    intent.putExtra("noFaceDetection", true);
    return intent;
  }

}

Related Tutorials