ios - 在 monotuch 中枚举图像资源

标签 ios xamarin.ios

有没有办法以编程方式枚举文件夹中的所有图像资源?

我想自动化动画图像序列创建过程并像这样加载图像:

var images = EnumResouceImages("Images/");
foreach(imgPath in images)
    UIImage myImg = UIImage.FromFile(imgPath);

最佳答案

一旦您知道应用程序的根目录,例如通过调用 NSBundle.MainBundle.BundleUrl.Path,您可以使用基类库 (BCL) 提供的 System.IO 类型来执行此操作。

例如这段代码:

foreach (var filename in Directory.EnumerateFiles (Path.Combine (NSBundle.MainBundle.BundleUrl.Path, "Images"), "*.png"))
    Console.WriteLine (filename);

将打印位于应用程序 Images/ 目录中的每个 .png 文件。

您可以根据自己的逻辑更改过滤器(例如 jpeg 或其他格式)、目录名称 (Images) 或处理 (Console.WriteLine)。

关于ios - 在 monotuch 中枚举图像资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9306231/

相关文章:

ios - 解雇ModalViewControllerAnimated时显示正确的UIView :completion: is called

objective-c - NSDictionary 不区分大小写 objectForKey :

c# - CLGeocoder.ReverseGecode 在 50 个请求后挂起

ios - 退出 iOS 应用程序(.monotouch-32 符号链接(symbolic link))

xamarin.ios - Monotouch - 在 map 上绘制 MKPolyline

ios - Monotouch 中是否有 NSString 的 "stringByReplacingCharactersInRange"方法?

iphone - 在 UIButton 上使用两个不同的控制事件

ios - 解开可选值 SWIFT 时为 nil

iphone - 从未完成 [GKAchievement loadAchievementsWithCompletionHandler :]

xamarin.ios - mvvmcross 中的海关绑定(bind)交叉 View