2016-02-29 126 views
0
File file = new File("/storage/emulated/0/BabyCareData/photo/20160229_161413.jpg"); 
if (file.exists()) { 
    views.setImageViewUri(R.id.imageAvatar, Uri.parse(file.getPath()));    
} 

我已檢查路徑和uri,它是正確的。 setImageViewUri不顯示圖片,但顯示白色屏幕(背景爲白色)。setImageViewUri不顯示圖片,但顯示圖像背景

+0

你必須創建位圖來設置views.setImageViewBitmap()。給位圖功能,而不是uri –

+0

@KhizarHayat我已經嘗試使用setImageViewBitmap(),但不是知府,它只有有效 – zys

+0

你有沒有給定圖像的位圖? –

回答

0

試試這個:

File file = new File(/storage/emulated/0/BabyCareData/photo/20160229_161413.jpg); 

if(file.exists()) 
{ 

    Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); 
    setBitmap(views,R.id.imageAvatar,myBitmap); 

} 

    private void setBitmap(RemoteViews views, int resId, Bitmap bitmap){ 
     Bitmap proxy = Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(), Bitmap.Config.ARGB_8888); 
     Canvas c = new Canvas(proxy); 
     c.drawBitmap(bitmap, new Matrix(), null); 
     views.setImageViewBitmap(resId, proxy); 
    } 
+0

爲什麼不「setImageViewBitmap」? – zys

+0

我們不知道視圖組。所以'ImageView myImage =(ImageView)findViewById(R.id.imageAvatar);'是錯誤 – zys

+0

檢查更新回答 – Jas

1

試試這個:

File file = new File("/storage/emulated/0/BabyCareData/photo/20160229_161413.jpg"); 
     if (file.exists()) { 
      Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); 
      views.setImageViewBitmap(R.id.imageAvatar, bitmap);    
     } 
+0

抱歉,我犯了一個錯誤,我使用的是setImageViewUri,我編輯了我的問題。謝謝! – zys

+0

我更新我的答案,請參閱並嘗試 –

+0

它不起作用。 – zys