使用ImageView显示图库

时间:2015-05-28 17:36:16

标签: java android 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" />

1 个答案:

答案 0 :(得分:1)

尝试:

Bitmap bitmap_photo = MediaStore.Images.Media.getBitmap(getContentResolver(),imageUri);