2012-06-04 59 views
0

我遇到圖片問題。我在picture=sites/default/files/arrow_green_right_0.png有一張照片。在我的應用程序中,我只能得到這個String。我想在我的imageView中顯示來自此字符串的圖片。我該怎麼做?如何從字符串顯示圖片

+0

沒有複製項目中的圖片? –

+0

把這個pictute放到可繪製的文件夾中 – budgie

+0

我不能那樣做。這張照片必須在這個地方。只有我得到的是這個字符串 – user1302569

回答

1

試試這個:

ImageView img = new ImageView(this); 
File file = new File(YOUR PATH TO THE IMAGE); 
if (file.exists()) { 
    img.setImageURI(Uri.fromFile(file)); 
} 
2

嗨你必須首先設置圖像的路徑,並確保你處理它與例外,以避免它崩潰。遵循下面的代碼: -

File imgFile = new File(「/sdcard/Images/test_image.jpg」); 
if(imgFile.exists()){ 

Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); 

ImageView myImage = (ImageView) findViewById(R.id.imageviewTest); 
myImage.setImageBitmap(myBitmap); 

}