2013-10-22 73 views
0

我想設置一個背景圖像,但不能從可繪製文件夾中,圖像來自內部存儲庫。不能從可繪製文件夾設置背景圖像

有沒有可能這樣做?

+3

爲什麼不呢?如果你知道它的路徑,就可以獲得一個'Bitmap'對象,然後從位圖中創建一個'BitmapDrawable'並且你有它。 – gunar

+0

+1 gunar,從圖庫中獲取圖像作爲位圖並在圖像視圖中顯示該位圖 –

+0

如何創建BitmapDrawable? – XZheng

回答

1

調用此

Intent intent = new Intent(); 
intent.setType("image/*"); 
intent.setAction(Intent.ACTION_GET_CONTENT); 
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE); 

你可以從活動開啓畫廊意圖,也處理OnActicityResult方法..... Try This link for solution

所以,現在setBacground您可以將位圖使用下面繪製代碼..

Drawable d = new BitmapDrawable(getResources(),bitmap); 
view.setBackground(d); 

我希望這可以幫助你......

+0

我會稍後再試。謝謝。 – XZheng

0

從圖庫中獲取圖像作爲位圖並在圖像視圖中顯示該位圖 這是一個非常好的tutorial從ImageView中的圖庫中顯示圖像。從活動