简体   繁体   English

无法将图像的URI路径放入Android Studio中的imageview

[英]Can't put an URI path of an image to imageview in Android Studio

I am trying to make two apps which communicate with each other via content provider. 我正在尝试制作两个通过内容提供程序相互通信的应用程序。 The content Provider is working fine and the data is getting transferred. 内容提供程序运行正常,并且正在传输数据。 The problem comes in the image path that I am sending via the content provider. 问题出在我通过内容提供者发送的图像路径中。

  values.put(StudentsProvider.IMG_URL,selectedImage.toString());

This is the data i am storing in the content provider. 这是我存储在内容提供商中的数据。 The selectedImage is the uri object. selectedImage是uri对象。 I am trying to retrieve this string in other app and displaying it in listview. 我试图在其他应用程序中检索此字符串并在listview中显示它。

        viewHolder.img1.setImageURI(Uri.parse(img[position])); 

img[position] contains the string sent by selectedImage.tostring(). img [position]包含selectedImage.tostring()发送的字符串。 The data is being transferred between the two apps but the image in not showing. 数据正在两个应用程序之间传输,但未显示图像。

class ViewHolder

{

    CircleImageView img1;

    ViewHolder(View v)
    {

        img1 = (CircleImageView) v.findViewById(R.id.profile_image);


    }


}

First compress the drawable to bitmap... 首先将可绘制对象压缩为位图...

Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
                                           R.drawable.icon_resource);

You can try drawable without compressing also. 您可以尝试可绘制而不压缩。

Then Use Glide library... 然后使用Glide库...

GlideApp
    .with(myFragment)
    .load(icon) //
    .centerCrop()
    .placeholder(myImageView)
    .into(myImageView);

More about Glide library.. https://github.com/bumptech/glide 有关Glide库的更多信息.. https://github.com/bumptech/glide

Hope it helps!! 希望能帮助到你!!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM