简体   繁体   English

如何从外部存储获取图像

[英]How get images from external storage

I have created a folder called Items in /mnt/sdcard/ , from where I want to find JPG images. 我在/mnt/sdcard/创建了一个名为Items的文件夹,从中我想从中找到JPG图像。 Then I want to display a ListView with all the names of the listed images. 然后,我想显示具有列出图像的所有名称的ListView Upon clicking on one of the names in the list, I would like the image from the path display in an ImageView . 单击列表中的名称之一后,我想要ImageView路径显示中的ImageView I have troubles finding the images. 我找不到图像。

How can I do this? 我怎样才能做到这一点?

The External Storage path differs from device to device and I strongly suggest you are not using /mnt/sdcard/ but rater Environment.ExternalStorageDirectory . 外部存储路径因设备而异,我强烈建议您不要使用/mnt/sdcard/而是使用ratingr Environment.ExternalStorageDirectory

You should be able to use normal C# file operations to get a list of files. 您应该能够使用正常的C#文件操作来获取文件列表。

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

You can use the filePaths to pass to your custom Adapter and inside that load the Bitmap s if you want to display them inside of the ListView : 如果要在ListView内显示它们,可以使用filePath传递给自定义的Adapter并在内部加载Bitmap

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

or you can simply use a SimpleAdapter and pass it the filePaths , which will then display them as strings. 或者,您可以简单地使用SimpleAdapter并将其传递给filePaths ,然后将其显示为字符串。

Then you just need to hook up the ItemClick event to get the position in the list clicked and load the correct Bitmap into an ImageView. 然后,您只需要挂接ItemClick事件即可获得单击列表中的位置,然后将正确的Bitmap加载到ImageView中。

Also please read http://docs.xamarin.com/recipes/android/resources/general/load_large_bitmaps_efficiently if you are using large images, as you have very limited resources. 另外,如果您使用的是大型图片,则请阅读http://docs.xamarin.com/recipes/android/resources/general/load_large_bitmaps_效率 ,因为您的资源非常有限。

A good resource for Custom List Adapters: http://redth.info/2010/10/12/monodroid-custom-listadapter-for-your-listview/ 自定义列表适配器的一个很好的资源: http : //redth.info/2010/10/12/monodroid-custom-listadapter-for-your-listview/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Android 的外部存储中获取图像? - How to fetch images from External Storage in Android? 从外部存储获取图像并将其显示在图库中 - Get images from external storage and display them in a Gallery 如何从 Flutter 的外部存储中获取文件? - How to get files from external storage in Flutter? 如何平滑地从外部存储器加载图像? - How to load images from external storage smooth with glide? 如何在颤振中显示来自外部存储路径的图像? - How to display images from a external storage path in flutter? Android-将外部存储中的图像列出到Recycleview中 - Android - List images from external storage into Recycleview 毕加索未从外部存储器加载图像 - Picasso is not loading images from the external storage Android从外部存储加载大图像 - Android load big images from external storage 如何从图库中隐藏FilePicker图像? 以及如何将这些图像存储在外部存储器的文件夹中? - How to Hide FilePicker images from Gallery? and How to store those images in a folder inside external storage? Android如何从外部存储获取资源标识符 - Android how to get resource identifier from external storage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM