![](/img/trans.png)
[英]Failed to save image from app assets folder to Gallery Folder in Android?
[英]Android Create Image Gallery from App Folder
我正在开发一个应用程序,而我的活动之一是截取我在/ data /应用程序文件夹中创建的文件夹中的所有图像的屏幕。 我想抓取所有照片,将它们以网格格式放置,然后当一个人单击某个照片时,将其放大到最大尺寸。 当然,当将新图像添加到文件夹时,此图库需要更改。
似乎做起来很简单,但我在实现此功能时遇到了一些麻烦,我一直在寻找许多不同的解决方案,但这些解决方案似乎都不对。
我假设这将是某种gridview / listadapter组合。
最好的解决方案是什么?
编辑
我已经研究了这些解决方案http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/ http://developer.android.com/guide/topics/ui/layout/gridview.html#例
但我的困惑是这样的代码
private Integer[] mThumbIds = {
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7
};
我要怎么做,因为图片数量会在我的应用文件夹中不断变化。 以及如何首先从该文件夹中加载图像哈哈
您是否看到过Android开发者网站中的缓存位图 ? 我认为它的作用类似于您想要的。 它还提供了示例代码。
您最好将图像存储在SD卡内的路径中,因为它们需要动态更改。 然后要从该路径获取图像路径,请使用类似以下内容的方法(假设您在该目录中只有图像):
File imagesDir = new File(Environment.getExternalStorageDirectory(), "yourpath");
for (File f : yourDir.listFiles()) {
if (f.isFile())
String image_path = f.getPath();
// make something with the name
}
另外,要从sd中的文件加载位图,请使用以下命令:
Bitmap b = BitmapFactory.decodeFile("your_image_path");
请记住加载位图的缩小版本以提高内存效率。 有关更多信息,请参见此处 。
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.