2013-03-08 36 views
0

我在/mnt/sdcard/中創建了一個名爲Items的文件夾,從中我想要查找JPG圖像。然後我想要顯示一個ListView,列出所有圖像的名稱。點擊列表中的其中一個名稱,我想從ImageView中顯示路徑中的圖像。我有麻煩找到圖像。如何從外部存儲器獲取圖像

我該怎麼做?

回答

1

外部存儲路徑因設備而異,我強烈建議您不要使用/mnt/sdcard/,而是使用評估者Environment.ExternalStorageDirectory

您應該可以使用普通的C#文件操作來獲取文件列表。

string[] filePaths = Directory.GetFiles(Environment.ExternalStorageDirectory, "*.jpg"); 

您可以使用文件路徑傳遞給您的自定義Adapter和負載內Bitmap■如果你想顯示他們ListView內:

using(var bitmap = BitmapFactory.DecodeFile(filePaths[position])) 
    imageView.SetImageBitmap(bitmap); 

,或者你可以簡單地使用一個SimpleAdapter並通過它filePaths,然後將它們顯示爲字符串。

然後,您只需要連接ItemClick事件以獲取點擊列表中的位置並將正確的Bitmap加載到ImageView中。

如果您使用的是大圖像,請閱讀http://docs.xamarin.com/recipes/android/resources/general/load_large_bitmaps_efficiently,因爲您的資源非常有限。

的自定義列表適配器一個很好的資源:http://redth.info/2010/10/12/monodroid-custom-listadapter-for-your-listview/

+0

YEEEES!非常感謝! – Frieurieud 2013-03-08 14:05:28

相關問題