所以我有一個加載庫,並使用此代碼選擇圖像的按鈕...ImageView的不顯示圖像從畫廊
public void getGalleryImage(View v){
Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivityForResult(intent, 1);
}
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();
galleryImage.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
但是,當它返回到原來的活動中,ImageView的還是沒有顯示任何東西。它不會給我任何錯誤,或者類似的東西。這裏的ImageView的XML ...
<ImageView
android:id="@+id/galleryImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
我怎樣才能讓它顯示?
我認爲[此鏈接] [1]會幫助你。 [1]:http://stackoverflow.com/questions/10860562/how-to-display-selected-gallery-image-in-imageview-in-android – 2015-01-26 18:06:59
檢查此主題http://stackoverflow.com/問題/ 3879992/get-bitmap-from-an-uri-android 所有的最好的 – AndroidRuntimeException 2015-01-26 18:09:14