如何设置图像位图而不直接使用“r.drawable.”?

92dk7w1h  于 2021-07-04  发布在  Java
关注(0)|答案(0)|浏览(193)

抱歉,如果标题有点模棱两可。
我正在使用设置imageview的图像 mImageView.setImageBitmap(BitmapFactory.decodeResource(context.getResources(), R.drawable.picture)); 我希望我能硬编码可提取的身份证,像这样: profilePicture.setImageBitmap(BitmapFactory.decodeResource(context.getResources(), 700036)); ,但这样做并不会在imageview中填充任何内容。我从androidstudio的autocomplete特性中得到了值700036。
我之所以这么做是因为我的应用程序依赖于一个启动文件——一个json文件,其中包含创建许多java对象所需的所有数据。以下是我的json文件的一个片段,如果有帮助的话:

[
    {
        "name": "Tommy Merlyn",
        "message": "Hi my name is Tommy",
        "profilePictureID": 700004,
           . . . etc
    },
    {
        "name": "Ricardo Diaz",
        "message": "The dragon",
        "profilePictureID": 700036,
           . . . etc
    }
]

这样,在解析json文件时,我可以读入profilepictureid并用 profilePicture.setImageBitmap(BitmapFactory.decodeResource(context.getResources(), profilePictureID)); 但是,由于某些原因,这并没有显示任何结果。
如何在不直接使用r.drawable.image的情况下填充imageview?或者有没有其他方法将图像“存储”在初始化文件中?提前多谢了!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题