Ehi, attualmente sto lavorando a uno sfondo animato e autorizzo l'utente a selezionare un'immagine che andrà dietro ai miei effetti.Come selezionare e ritagliare un'immagine in Android?
Attualmente ho:
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.putExtra("crop", "true");
startActivityForResult(i, 1);
E poco meno che:
@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();
}
}
Quando il mio codice è Ran, Logcat mi dice che SelectedImage è nullo. Se io commento la
i.putExtra("crop", "true"):
Logcat non mi dà l'eccezione puntatore nullo, e sono in grado di fare ciò che voglio con l'immagine. Quindi, qual è il problema qui? Qualcuno ha qualche idea su come posso risolvere questo problema? Grazie per il tuo tempo.
Ho la stessa domanda, e questa discussione aiuta, http://stackoverflow.com/questions/8238460/android-2-1-crop-image-fail – user538565
un altro thread simile: http: //stackoverflow.com/questions/12758425/how-to-set-the-output-image-use-com-android-camera-action-crop/ – hcpl