[英]Display image gallery with ImageView
我要這樣做:按下按鈕,打開圖庫,選擇一張圖片,它出現在程序ImageView中。 選定的圖片所有作品僅顯示為空白,只有空白區域。
//upload photo
uploadPhoto.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
final int SELECT_PHOTO = 1234;
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case 1234:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
ImageView photoRegistration = (ImageView) findViewById(R.id.testSet);
photoRegistration.setImageURI(selectedImage);
}
}
}
XML
<ImageView
android:id="@+id/testSet"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:src="@drawable/common_signin_btn_icon_pressed_light" />
嘗試:
位圖bitmap_photo = MediaStore.Images.Media.getBitmap(getContentResolver(),imageUri);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.