gpt4 book ai didi

java - 使用 ImageView 显示图库

转载 作者:行者123 更新时间:2023-12-01 11:29:43 26 4
gpt4 key购买 nike

我想这样做:按下按钮打开图库,选择一张图片,它就会出现在程序 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);

关于java - 使用 ImageView 显示图库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30513456/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com