簡體   English   中英

Android從App文件夾創建圖片庫

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM