繁体   English   中英

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

[英]Android - User added image with ID similar to “R.Drawable”

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

我班的地方

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));

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

new Place(
            ((EditText) findViewById(R.id.et_name)).getText().toString(),
            ((EditText) findViewById(R.id.et_country)).getText().toString(),
            ((EditText) findViewById(R.id.et_about)).getText().toString(),
            ((EditText) findViewById(R.id.et_sights)).getText().toString(),
            *Here I need to add image*
         );

我已经在位图中准备了图像,但是我不知道如何将其放入此处。 我目前所知道的一切是我无法在正在运行的程序中将任何内容添加到drawable文件夹中。 很抱歉,如果这是重复线程。 如果是这样,请在此处为我发布一个链接。 谢谢。

正如我在我的问题下所写的那样,在这种情况下,像这样使用res ID并不是一个好主意。 我重新制作了项目,以便数据库可以使用Blobs。

只需通过ByteArrayOutputStream并通过BitmapFactory.decodeByteArray(...)解码即可。

Class Place现在使用Bitmap而不是Integer

暂无
暂无

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

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