首页 > 解决方案 > 使用毕加索,我试图从存储在数据库中的图像路径在 imageview 中设置图像

问题描述

我已将图像的路径存储在 sqlite 数据库(例如 R.drawable.img)中,但是当我尝试检索图像路径并将其用作 picasso 的路径时,我没有获取图像但正在显示路径.

   //image is the column name for the path of image in database
    ImageView imageview=(ImageView)findViewById(R.id.imagetext);
    Context context = imageText.getContext();
    String path="image";
    Picasso.with(context)
            .load(path)
            .placeholder(R.mipmap.ic_launcher)
            .error(R.mipmap.ic_launcher)
            .resize(50,50)
            .into(imageview);

标签: android

解决方案


如果您想使用其名称获取可绘制 id,您可以执行以下操作:

int id=getResources().getIdentifier(path,"drawable",getPackageName());

然后以您想要的方式使用 id 。

您也可以尝试将图像直接设置为imageview

imageView.setImageBitmap(BitmapFactory.decodeResource(getResources(),getResources().getIdentifier("image","drawable",getPackageName())));

PS:我认为你不需要毕加索。


推荐阅读