Reputation: 390
I'm creating an offline application in Xamarin Forms, I'm currently saving images in specific projects (Android and iOS) and would like to load them all into a ListView. I tried using the following code:
IEnumerable <string> images = Directory.EnumerateFiles("Resources", "*.jpg", SearchOption.AllDirectories);
But I was unsuccessfully, could anyone help me please?
Thank you.
Upvotes: 0
Views: 1045
Reputation: 390
I was able to solve my problem with the following code:
public IEnumerable<string> EnumerateImagesFromResource(Func<FieldInfo, bool> filter)
{
return typeof(Resource.Drawable).GetFields().Where(filter).Select(s => s.Name);
}
Upvotes: 0
Reputation: 14956
if you want to do like this,i suggest you to save the images into Assets folder,and you could iterate the folder and filter with .png
.
for example in Android :
List<System.IO.Stream> streamList = new List<System.IO.Stream>();
AssetManager assetManager = Assets;
string[] images = assetManager.List("");
for (int i = 0; i < images.Length; i++)
{
if (images[i].EndsWith(".png"))
{
using (StreamReader sr = new StreamReader(assetManager.Open(images[i])))
{
streamList.Add(sr.BaseStream);
}
}
}
Assets in android:
you could get the list of image stream by DependencyService or MessagingCenter
Upvotes: 1