简体   繁体   English

Xamarin iOS 哪里是图库中的图像

[英]Xamarin iOS where are images from gallery

I'm looking for a way to loop for each image that issaved on the iOS device.我正在寻找一种方法来循环 iOS 设备上的每个图像。

I have already tried with我已经尝试过

var library = new ALAssetsLibrary();

library.Enumerate(ALAssetsGroupType.Library, GroupEnumerator, Console.WriteLine);
library.Enumerate(ALAssetsGroupType.Album, GroupEnumerator, Console.WriteLine);
library.Enumerate(ALAssetsGroupType.SavedPhotos, GroupEnumerator, Console.WriteLine);
library.Enumerate(ALAssetsGroupType.All, GroupEnumerator, Console.WriteLine);

But when I debug all list are empty.但是当我调试所有列表时都是空的。

How can I retrieve a list of all images saved in the device (gallery)?如何检索保存在设备(图库)中的所有图像的列表?

Here are complet class code from where i (try to) list all images这是我(尝试)列出所有图像的完整类代码

using AssetsLibrary;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace AG.iOS.Services
{
    public class iOSGalleryContent : IGalleryContent
    {
        public static readonly List<string> ImageExtensions = new List<string> { ".JPG", ".JPE", ".BMP", ".GIF", ".PNG" };
        List<string> ImagesNames = new List<string>();
        public List<string> GetImagesNames()
        {
            var library = new ALAssetsLibrary();
            library.Enumerate(ALAssetsGroupType.Library, GroupEnumerator, Console.WriteLine);
            library.Enumerate(ALAssetsGroupType.Album, GroupEnumerator, Console.WriteLine);
            library.Enumerate(ALAssetsGroupType.SavedPhotos, GroupEnumerator, Console.WriteLine);
            library.Enumerate(ALAssetsGroupType.All, GroupEnumerator, Console.WriteLine);

            return ImagesNames;



        }

        private void GroupEnumerator(ALAssetsGroup group, ref bool shouldStop)
        {
            if (group == null)
            {
                shouldStop = true;
                return;
            }
            if (!shouldStop)
            {
                group.Enumerate(AssetEnumerator);
                shouldStop = false;
            }
        }

        private void AssetEnumerator(ALAsset asset, nint index, ref bool shouldStop)
        {
            if (asset == null)
            {
                shouldStop = true;
                return;
            }
            if (!shouldStop)
            {
                ImagesNames.Add(asset.AssetUrl.AbsoluteString);
                Console.WriteLine(String.Format("Item[{0}] : {1}", index, asset.ToString()));
                shouldStop = false;
            }
        }
    }
}

Here's a minimal code example that gets images from all albums.这是一个从所有相册中获取图像的最小代码示例。 It should be relatively easy to modify this for your purposes.为您的目的修改它应该相对容易。 I haven't tried the code but it should be ok.我没有试过代码,但应该没问题。

assetsLibrary = new ALAssetsLibrary();
photoAssets = new List<ALAsset>();

assetsLibrary.Enumerate (ALAssetsGroupType.Album, (ALAssetsGroup group, ref bool stop) => {
    group.SetAssetsFilter (ALAssetsFilter.AllPhotos);
    group.Enumerate ((ALAsset asset, nint index, ref bool st) => {
        int notfound = Int32.MaxValue;
        if (asset != null && index != notfound) {
            photoAssets.Add (asset);
        }
    });
});

Xamarin has a Xamarin.iOS sample that does this: MediaNotes Xamarin 有一个 Xamarin.iOS 示例可以执行此操作: MediaNotes

Strangely the code work perfectly...Debuger point me to wrong direction because he can not happen to show me the content of the stringUrl List.奇怪的是,代码运行良好......调试器指向错误的方向,因为他无法向我展示 stringUrl 列表的内容。

So, be free to use it.所以,请随意使用它。 It does what it is supposed to do.它做它应该做的事情。

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

相关问题 如何在iOS Xamarin Studio中将图像从画廊上传到Web API 2 - How to upload image from gallery to web api 2 in ios xamarin studio Xamarin-是否有与Android可用的Photokit(iOS)类似的框架,或者是获取图库中所有图像文件流的好方法? - Xamarin - Is there a similar framework to Photokit (iOS) available for Android, or a good way to get the filestream of all images in the gallery? Xamarin IOS-Xamarin IOS中的轮播视图(图片) - Xamarin IOS - Carousel View(Images) In Xamarin IOS 如何从 Xamarin Forms 中的图库中 select 多张图片并保存到所需的文件路径? - How to select multiple images from gallery in Xamarin Forms and save to desired file path? Xamarin IOS编码和解码Base64的图像 - Xamarin IOS Encoding/Decoding Images from and to Base64 Xamarin iOS-从捆绑或文件夹中获取所有图像 - Xamarin iOS - Get all images from Bundle or folder 如何以 xamarin 形式从图库中选择图像? - How to select an image from gallery in xamarin forms? 能够拍摄或 Select 照片来自 Xamarin 中的图库 - Ability to Take or Select Photo from Gallery in Xamarin C#Xamarin.Android图像显示在文件管理器中,而不显示在图库中 - C# Xamarin.Android images are displayed in the file manager and not in the gallery Xamarin 表单如何从图库中选择图像 - Xamarin forms How to pick a Image from Gallery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM