【发布时间】:2019-02-13 18:52:28
【问题描述】:
我正在尝试从图库中添加图片以显示在我的应用程序中。但是在我从图库中选择图像后它没有显示。它没有显示任何错误并在我的设备上成功运行。
私有静态 int RESULT_LOAD_IMAGE=1;
public void addImage(View view){ Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(意图,RESULT_LOAD_IMAGE); }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if((requestCode == RESULT_LOAD_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();
ImageView imageView = (ImageView) findViewById(R.id.memeImage);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
【问题讨论】:
标签: android