将图像从一个片段传递到另一个片段并在该片段中显示图像

将图像从一个片段传递到另一个片段并在该片段中显示图像

问题描述:

从中选择图像的第一个片段

           iv.setImageURI(Uri.fromFile(pictureFile));
                String stringUri;
                stringUri = pictureFile.toString();

                FreeFragment ldf = new FreeFragment ();
                Bundle args = new Bundle();
                args.putString("Image", stringUri);
                ldf.setArguments(args);
                Log.d("Passing image", String.valueOf(args));
                getFragmentManager().beginTransaction().add(R.id.container, ldf).commit();

第二个片段接收图像并显示

 String bbb = getArguments().getString("Image");
    Bitmap bitmap = BitmapFactory.decodeFile(bbb);
    iv.setImageBitmap(bitmap);


将文件路径发送到下一个片段

Send file path to next Fragment

String stringUri = pictureFile.getAbsolutePath();

FreeFragment ldf = new FreeFragment ();
Bundle args = new Bundle();
args.putString("Image", stringUri);
ldf.setArguments(args);

getFragmentManager().beginTransaction().add(R.id.container, ldf).commit();

在你的NextFragment中你可以收到它并设置如下

In your NextFragment u can receive it and set as below

String imgPath = getArguments().getString("Image");
Bitmap bitmap = BitmapFactory.decodeFile(new File(imgPath));
iv.setImageBitmap(bitmap);