如何使用sqlite数据库中的图像路径将图像从drawable文件夹设置为imageview?

问题描述:

任何人都知道如何使用来自sqlite数据库的图像路径将图像从drawable文件夹设置为imageview? 任何帮助将不胜感激。示例代码将会很有帮助。谢谢。 =)如何使用sqlite数据库中的图像路径将图像从drawable文件夹设置为imageview?

+0

如果图像是在你的文件夹绘制,那么你应该使用它的ID设置,像'R.drawable.your_img'你不应该需要它的路径。你能详细阐述一下你试图达到的目标吗? – FoamyGuy 2012-07-30 02:33:27

您可以从文件中获取Bitmap对象,并使用它来设置图像视图。 下面的代码:

String img_path = get from your database 
    ... 
    Bitmap bmp = BitmapFactory.decodeFile(img_path); 
    //use it. 
    yourimgview.setImageBitmap(bmp); 

^_^

ImageView imageView = (ImageView) findViewById(R.id.imageView); 

String test = "imageName"; // store only image name in database(means not store "R.drawable.image") like "image". 
      int id = getResources().getIdentifier("projectPackageName:drawable/" + test, null, null); 
      imageView.setImageResource(id);