Android - 用户添加的图片ID与“R.Drawable”类似

时间:2018-03-15 19:17:18

标签: java android android-studio

我一直在尝试找到索引用户添加图片的解决方案,因为它在默认文件夹(res \ drawables)中。

我的课程

gc.collect()

以编程方式添加地点

Place(String name, String country, String info, String sights, int photoId)
{
    this.name = name;
    this.country = country;
    this.info = info;
    this.sights = sights;
    this.photoId = photoId;
}

以编程方式但正在运行的应用添加位置

new Place("Paris", "France", getString(R.string.paris), getString(R.string.paris_sighs), R.drawable.paris));

我在位图中准备了图像,但我不知道怎么能把它放在这里。我目前所知道的一切是我无法在运行程序中向drawable文件夹添加任何内容。如果这是双重线程,我很抱歉。如果是这样,请在这里发布链接给我。感谢。

1 个答案:

答案 0 :(得分:0)

正如我在我提出的问题中写的那样,在这种情况下使用res ID是不好的主意。我重新制作了我的项目,以便数据库正在使用Blob。

简单地通过ByteArrayOutputStream进行压缩并通过BitmapFactory.decodeByteArray(...)进行解码。

Class Place现在正在使用Bitmap而不是Integer