Jak wybrać i przyciąć obraz w Androidzie?
Hej, obecnie pracuję nad żywą tapetą i pozwalam użytkownikowi wybrać obraz, który będzie odpowiadał moim efektom.
Obecnie mam:
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.putExtra("crop", "true");
startActivityForResult(i, 1);
I nieco poniżej:
@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();
}
}
Kiedy mój kod jest uruchomiony, Logcat mówi mi, że selectedImage ma wartość NULL. Jeśli komentuję
i.putExtra("crop", "true"):
Logcat nie daje mi wyjątku zerowego wskaźnika i jestem w stanie zrobić z obrazem to, co chcę. Więc w czym problem? Czy ktoś ma jakiś pomysł, jak mogę to naprawić? Dziękuję za Twój czas.