简体   繁体   English

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

[英]Passing image from one fragment to a another fragment and display image in that fragment

First fragment from which image is selected 从中选择图像的第一个片段

           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();

Second fragment receiving image and displaying it 第二个片段接收图像并显示

 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();

In your NextFragment u can receive it and set as below 在您的NextFragment中,您可以接收它并进行如下设置

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

Try getting your bundle in second fragment like this 尝试像这样在第二个片段中获取捆绑包

    Bundle bundle = this.getArguments();
if (bundle != null) {
    String s = bundle.getString(key, defaulValue);
}

Also check this link for further references Passing bundle in fragments 还要检查此链接以获取更多参考

Bundle bundle = this.getIntent().getExtras();
String strPic = bundle.getString("Image");
File picFile = new File("your file path"+strPic);
if(picFile.exists())
{           
   iv.setImageURI(Uri.fromFile(picFile));
}           

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从一个片段移动到另一个片段,并传递一个字符串和一个图像 - moving from one fragment to another passing a string and an image 如何将选定的图像从一个片段传递到另一个片段 - How to pass selected image from one fragment to another fragment 如何将图像从一个片段发送到另一个片段? - How to send image from one fragment to another? 从一个片段传递到另一个 - Passing from one fragment to another 如何在一个片段中添加图像并将其显示在另一个片段中/通过 android 中的捆绑包传递图像 - how to add image in one fragment and display it in another fragment/pass image through bundle in android 将数据从一个片段传递到另一个片段,从 FirebaseRecyclerAdapter - Passing data from one fragment to another fragment from FirebaseRecyclerAdapter 如何将图片库从片段传递到另一个活动? - How to passing Image Gallery from fragment into another activity? Java将数据从一个片段的Lis​​tView传递到另一个片段 - Java Passing Data From One Fragment's ListView To Another Fragment 从另一个片段传递到片段时,应用程序冻结一秒钟 - App freezes for a second when passing to a fragment from another one fragment 将复选框输入从一个片段传递到同一活动中的另一个片段 - Passing checkbox input from one fragment to another fragment in the same activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM