I have code to crop an image, like this :
public void doCrop(){
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setType("image/");
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent,0);
int size = list.size();
if (size == 0 ){
Toast.makeText(this, "Cant find crop app").show();
return;
} else{
intent.setData(selectImageUri);
intent.putExtra("outputX", 300);
intent.putExtra("outputY", 300);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
if (size == 1) {
Intent i = new Intent(intent);
ResolveInfo res = list.get(0);
i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
startActivityForResult(i, CROP_RESULT);
}
}
}
public void onActivityResult (int requestCode, int resultCode, Intent dara){
if (resultCode == RESULT_OK){
if (requestCode == CROP_RESULT){
Bundle extras = data.getExtras();
if (extras != null){
bmp = extras.getParcelable("data");
}
File f = new File(selectImageUri.getPath());
if (f.exists()) f.delete();
Intent inten3 = new Intent(this, tabActivity.class);
startActivity(inten3);
}
}
}
from what i have read, the code intent.putExtra("outputX", 300); intent.putExtra("outputY", 300); is use to set the resolution of crop result, but why i can’t get the result image resolution higer than 300×300? when I set the intent.putExtra("outputX", 800); intent.putExtra("outputY", 800); the crop function has no result or crash, any idea for this situation?
the log cat say “! ! ! FAILED BINDER TRANSACTION ! ! !
That Intent is not part of the public Android API and is not guaranteed to work on all devices. It was used in earlier versions of android 1.x and 2.x but it’s not used anymore and is not recommended. That is probably why it’s crashing all over the palce or working improperly.
Use methods such as
Bitmap.createBitmap(..)orBitmap.createScaledBitmap(..)to create a resized or cropped version of your original image. These are part of the Android API and are guaranteed to work.See official docs here and here
To crop a bitmap, you can use
Bitmap.createBitmap(Bitmap, int x, int y, int width, int height). For example, if you need to crop 10 pixels from each side of a bitmap then use this:If you need to show the selector to the user. Then you can do something like this:
code from here