从Android文件夹中加载所有图像 [英] Load all images from folder in Android

查看:34
本文介绍了从Android文件夹中加载所有图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不知道文件名称的情况下加载文件夹中的所有图像并将它们存储到整数向量中 - 在运行时.

I would like to load all images in a folder without knowing the names of the files and store them into a Integer vector - at runtime.

事实上,我需要与本示例中所做的相同:http://developer.android.com/resources/tutorials/views/hello-gridview.html但是在运行时并且不知道文件的名称.

In fact, i need the same as it is done in this example: http://developer.android.com/resources/tutorials/views/hello-gridview.html But at runtime and without knowing the names of the files.

有什么帮助吗?

在您回答之后,我知道该怎么做...但我不知道如何以与示例相同的方式进行:

After your answers i know how to do it... but i dont know how to go on in the same way as the example:

如何将图像保存在整数数组而不是可绘制数组或类似数组中?.这是我对 drawable 的尝试: DrawArray[i] = Drawable.createFromPath(fileArray[i].getPath());但我想用整数来做它以适应上面的链接!

How could i keep the images in an integer array instead of an drawable array or similar?. Here is my try with drawable: DrawArray[i] = Drawable.createFromPath(fileArray[i].getPath()); But i would like to do it with integer to fit with the link above!

提前致谢

一般解决方案:http://www.anddev.org/viewtopic.php?t=575

推荐答案

要获取特定文件夹的所有文件,请使用 list()-File 的方法-类,列出指定目录下的所有文件.

To get all files of a specific folder, use the list()-method of the File-class, which lists all Files of the specified directory.

要创建位图(然后可以绘制),您可以使用 BitmapFactory-class.

To create a Bitmap (which can then be drawn), you can use the BitmapFactory-class.

之后,您需要创建自己的适配器(如链接教程中所示)来显示您的位图.

After that, you'll need to create your own Adapter (as shown in the linked tutorial) to show your Bitmaps.

这篇关于从Android文件夹中加载所有图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆