Я пытаюсь установить изображение в изображение, которое пользователь выбирает из своей галереи. Однако все изображения, похоже, загружаются в мое изображение, за исключением случаев, когда я выбираю изображение из папки камеры. Он не помещает изображение в мое изображение. Обратитесь к следующему изображению http://i.stack.imgur.com/h6QGG.jpgИзображение папки камеры не отображается в imageview
Зова намерения
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.INTERNAL_CONTENT_URI);
// Start the Intent
Log.d(TAG,"STARTING ACTIVITY FOR RESULT");
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
OnActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
Log.d(TAG,"IN ON ACTIVIY RESULT");
super.onActivityResult(requestCode, resultCode, data);
try {
Log.d(TAG, "IN INTERESTS ON ACTIVITY RESULT");
if (requestCode == RESULT_LOAD_IMAGE && resultCode == Activity.RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContext().getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
File file = new File(picturePath);
bmOptions.inJustDecodeBounds = true;
Bitmap original = BitmapFactory.decodeFile(picturePath);
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
Bitmap newBm = Bitmap.createScaledBitmap(original, 900, 1280, true);
newBm.compress(Bitmap.CompressFormat.JPEG, 90, ostream);
ostream.close();
BitmapFactory.decodeFile(picturePath, bmOptions);
iconpic.setImageBitmap(newBm);
Toast.makeText(getContext(), picturePath, Toast.LENGTH_SHORT)
.show();
cursor.close();
SharedPreferences appPrefs = getContext().getSharedPreferences("com.example.gcmclient_preferences", Context.MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = appPrefs.edit();
prefsEditor.putString("iconPath", picturePath);
prefsEditor.commit();
// String picturePath contains the path of selected Image
}
}
catch (Exception e){
e.printStackTrace();
}
}
Helo, вместо файла декодирования. вы можете установить выбранную путь файла в imageview с помощью SetImageUri. –
Это не сработало @SreeReddyMenon –