将uri传递到另一个活动并将其转换为图像 [英] pass uri to another activity and convert it to image

查看:85
本文介绍了将uri传递到另一个活动并将其转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将图像的 uri 路径发送到另一个活动并将其转换为图像.我尝试了以下

How to send a uri path of an image to another activity and convert it to image. I tried the below

  protected void onActivityResult(int requestCode, int resultCode, Intent data) {

             super.onActivityResult(requestCode, resultCode, data);

              if (requestCode == 1 && resultCode == RESULT_OK && data != null && data.getData() != null) {

                  //file name
                     Uri selectedImage = data.getData();

                     Intent i = new Intent(this,
                              AddImage.class);
                    i.putExtra("imagePath", selectedImage);
                    startActivity(i);

像这样得到它

 String imagePath = getIntent().getStringExtra("imagePath");
            imageview.setImageURI(Uri.parse(imagePath ));

推荐答案

将您 URI 转换为String,同时添加到如下所示的 Intent

Convert you URI to String while adding to Intent like given below

i.putExtra("imagePath", selectedImage.toString());

,然后在您的 NextActivity 中获取 String ,然后像->

and in your NextActivity get the String and convert back to URI like ->

Intent intent = getIntent(); 
String image_path= intent.getStringExtra("imagePath"); 
Uri fileUri = Uri.parse(image_path) 
imageview.setImageURI(fileUri) 

这篇关于将uri传递到另一个活动并将其转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆