2012-07-30 63 views
0

任何人都知道如何使用來自sqlite數據庫的圖像路徑將圖像從drawable文件夾設置爲imageview? 任何幫助將不勝感激。示例代碼將會很有幫助。謝謝。 =)如何使用sqlite數據庫中的圖像路徑將圖像從drawable文件夾設置爲imageview?

+0

如果圖像是在你的文件夾繪製,那麼你應該使用它的ID設置,像'R.drawable.your_img'你不應該需要它的路徑。你能詳細闡述一下你試圖達到的目標嗎? – FoamyGuy 2012-07-30 02:33:27

回答

0

您可以從文件中獲取Bitmap對象,並使用它來設置圖像視圖。 下面的代碼:

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

^_^

1
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); 
相關問題