如何从UIImage的数组提取图像文件名

如何从UIImage的数组提取图像文件名

本文介绍了斯威夫特:如何从UIImage的数组提取图像文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有UIImage的数组,像这样:

If I have an array of UIImage like so:

newImageArray = [UIImage(named:"Red.png")!,
        UIImage(named:"Green.png")!,
        UIImage(named:"Blue.png")!, UIImage(named:"Yellow.png")!]

我怎样才能提取或确定某一指数以后的图像的文件名?例如:

How can I extract or determine the filename of an image of a certain index later on? For example:

println("The first image is \(newImageArray[0])")

而不是返回可读的文件名,则返回:

Instead of returning a readable filename, it returns:

The first image is <UIImage: 0x7fe211d2b1a0>

我可以转换这个输出成可读的文本,或者是有距离的UIImage数组?

Can I convert this output into readable text, or is there a different method of extracting filenames from UIImage arrays?

推荐答案

我有环顾四周,因为这在过去一直是个问题,我也。的UIImage不存储图像的文件名。我所做的,解决这个问题是不是图像阵列我用一本字典的键名和值作为图像。在我的for循环我摘录了每个项目的键和值到一个数组和对待他们。

I have had a look around as this has been a problem for me in the past also. UIImage does not store the filename of the image. What I did to solve the issue was instead of an image array I used a dictionary with the key as the filename and the value as the Image. In my for loop I extracted the key and value of each item into a tuple and dealt with them.

我不再有code,但作为一个快速模仿了什么,我没看到下面,(我希望这符合您的要求,因为我知道每个应用程序是不同的)

I no longer have the code but as a quick mock up of what I did see below, (I hope this fits your requirements as I know every application is different)

var imageDictionary = ["image1.png": UIImage(named: "image1.png"),
     "image2.png": UIImage(named: "image2.png")]

,然后循环将看起来像:

and then the for loop will look like:

for (key, value) in imageDictionary {
    println(key) // Deal with Key
    println(value) // Deal with Value
}

......按我说的这个工作对我来说,我需要它的情况下,我希望你也可以用它!

...as I say this worked for me and the scenario I needed it for, I hope you can use it also!

祝你好运!

这篇关于斯威夫特:如何从UIImage的数组提取图像文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 05:33