简体   繁体   English

Android从App文件夹创建图片库

[英]Android Create Image Gallery from App Folder

I am working on an app and one of my activities is a screen that grabs all the images in a folder I made in the /data/ application folder. 我正在开发一个应用程序,而我的活动之一是截取我在/ data /应用程序文件夹中创建的文件夹中的所有图像的屏幕。 I would like to to grab all the photos lay them out in a grid format and then when a person clicks on one it blows it up to full size. 我想抓取所有照片,将它们以网格格式放置,然后当一个人单击某个照片时,将其放大到最大尺寸。 Of course this gallery needs to change when new images are added to the folder. 当然,当将新图像添加到文件夹时,此图库需要更改。

Seems like it would be some thing simple to do but I am having some trouble implementing this I keep finding a lot of different solutions non of which seem quite right. 似乎做起来很简单,但我在实现此功能时遇到了一些麻烦,我一直在寻找许多不同的解决方案,但这些解决方案似乎都不对。

I'm assuming it would be some sort of gridview/listadapter combination. 我假设这将是某种gridview / listadapter组合。

What would the best solution to this problem? 最好的解决方案是什么?

EDIT 编辑

I have looked into these solutions http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/ http://developer.android.com/guide/topics/ui/layout/gridview.html#example 我已经研究了这些解决方案http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/ http://developer.android.com/guide/topics/ui/layout/gridview.html#例

but my confusion is code like this 但我的困惑是这样的代码

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
};

What do I do about this since the amount of images will be constantly changing in my app folder. 我要怎么做,因为图片数量会在我的应用文件夹中不断变化。 And how do I load the images out of that folder in the first place haha 以及如何首先从该文件夹中加载图像哈哈

Have you seen the the Caching Bitmaps in Android Developers site? 您是否看到过Android开发者网站中的缓存位图 I think it does something similar to what you want. 我认为它的作用类似于您想要的。 It also provides the code of the example. 它还提供了示例代码。

You should better store you images in a path inside the sd card, since they need to change dynamically. 您最好将图像存储在SD卡内的路径中,因为它们需要动态更改。 Then to get the image paths from that path, use something like this (asssuming that you only have images in that directory): 然后要从该路径获取图像路径,请使用类似以下内容的方法(假设您在该目录中只有图像):

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
}

Also, to load a bitmap from a file in your sd, use something like this: 另外,要从sd中的文件加载位图,请使用以下命令:

Bitmap b = BitmapFactory.decodeFile("your_image_path");

Just keep in mind to load a downscaled version of the bitmap for memory efficiency. 请记住加载位图的缩小版本以提高内存效率。 See here for more information. 有关更多信息,请参见此处

Hope it helps. 希望能帮助到你。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM