Android : How to Crop Image Selected From Gallery

on Friday, September 12, 2014


i want to use Crop Intent i can image Selected From Gallery When I Use Crop intent


then My app Is Crashed When i removed Crop Intent Then Its Working Fine but I want to crop Image ... here is My Logcat Error



09-12 15:37:08.909: E/AndroidRuntime(25459): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { (has extras) }} to activity {com.example.upload_image/com.example.upload_image.MainActivity}: java.lang.NullPointerException
09-12 15:37:08.909: E/AndroidRuntime(25459): at android.app.ActivityThread.deliverResults(ActivityThread.java:3149)
09-12 15:37:08.909: E/AndroidRuntime(25459): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3192)
09-12 15:37:08.909: E/AndroidRuntime(25459): Caused by: java.lang.NullPointerException
09-12 15:37:08.909: E/AndroidRuntime(25459): at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1094)


And Here Is My Code ..Please tell Where I m Doing Wrong



public void selectImageFromGallery() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);

intent.putExtra("crop", "true");
intent.putExtra("aspectX", 0);
intent.putExtra("aspectY", 0);
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 150);


try {

intent.putExtra("return-data", true);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),
PICK_IMAGE);
} catch (ActivityNotFoundException e) {
// Do nothing for now
}
}



/* startActivityForResult(Intent.createChooser(intent, "Select Picture"),
PICK_IMAGE);
}*/


/**
* Retrives the result returned from selecting image, by invoking the method
* <code>selectImageFromGallery()</code>
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == PICK_IMAGE && resultCode == RESULT_OK
&& null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };

Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();

decodeFile(picturePath);

}
}

0 comments:

Post a Comment