【发布时间】:2021-12-16 18:54:16
【问题描述】:
我想在一个片段中选择图像并将其显示在另一个片段中。
我怎样才能做到这一点。
我的代码是这样,但不工作
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, 100);
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
Uri imageUri;
if (resultCode == RESULT_OK && requestCode == 100){
imageUri = data.getData();
file1path = imageUri.getPath();
TVfrontimg.setText(file1path);
}
}
我使用 bundle 发送这个
Bundle bundle = new Bundle();
bundle.putString("image1", file1path);
registerPartThreeFragment.setArguments(bundle);
transaction.replace(R.id.FLcontainer, registerPartThreeFragment);
transaction.addToBackStack(null);
transaction.commit();
在另一个片段中
String imgPath = getArguments().getString("image1");
Bitmap bitmap = BitmapFactory.decodeFile(String.valueOf(new File(imgPath)));
imageview.setImageBitmap(bitmap);
但它不起作用。请帮助。
它给了我这个错误
2020-05-30 00:16:20.808 8995-8995/com.example.deliveryapp E/BitmapFactory:无法解码流:java.io.FileNotFoundException:/raw/storage/emulated/0/DCIM/Camera/IMG_20200319_173033.jpg (没有这样的文件或目录)
【问题讨论】:
标签: android