android - 使用毕加索,我试图从存储在数据库中的图像路径在 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);
解决方案
如果您想使用其名称获取可绘制 id,您可以执行以下操作:
int id=getResources().getIdentifier(path,"drawable",getPackageName());
然后以您想要的方式使用 id 。
您也可以尝试将图像直接设置为imageview
imageView.setImageBitmap(BitmapFactory.decodeResource(getResources(),getResources().getIdentifier("image","drawable",getPackageName())));
PS:我认为你不需要毕加索。
推荐阅读
- python-2.7 - 如何使用 MySQLdb 插入 cp1252 字符?
- arangodb - arangodb kill 查询不起作用 require("org/arangodb/aql/queries").kill("2418")
- java - JSON 属性的自定义命名 - JAX-RS 解组
- sql-server - 使用 SSIS 进行数据迁移(64 位 oracle)
- node.js - mocha, chai 测试 nodejs 中的帖子
- react-native - 在 react-native-maps 上显示自定义图像作为标记
- ios - 如何设置自动布局约束,使 UIImageView 的高度等于父视图的高度?
- django - 是否可以从 Chrome 扩展程序进行重定向 + POST
- scala - 在 Spark 中按 RDD 的一列排序
- ruby-on-rails - Rspec before(:each) 有效,但 before(:all) 无效