How to select and crop an image in android?
Posted
by Guy
on Stack Overflow
See other posts from Stack Overflow
or by Guy
Published on 2010-01-18T09:33:13Z
Indexed on
2010/04/13
0:02 UTC
Read the original article
Hit count: 429
Hey, I am currently working on a live wallpaper and I allow the user to select an image which will go behind my effects.
Currently I have:
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.putExtra("crop", "true");
startActivityForResult(i, 1);
And slightly under that:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1)
if (resultCode == Activity.RESULT_OK) {
Uri selectedImage = data.getData();
Log.d("IMAGE SEL", "" + selectedImage);
// TODO Do something with the select image URI
SharedPreferences customSharedPreference = getSharedPreferences("imagePref", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = customSharedPreference.edit();
Log.d("HO", "" + selectedImage);
editor.putString("imagePref", getRealPathFromURI(selectedImage));
Log.d("IMAGE SEL", getRealPathFromURI(selectedImage));
editor.commit();
}
}
When my code is ran, Logcat tells me that selectedImage is null. If I comment out the
i.putExtra("crop", "true"):
Logcat does not give me the null pointer exception, and I am able to do what I want with the image. So, what is the problem here? Does any one have any idea how I can fix this? Thanks, for your time.
© Stack Overflow or respective owner