0

我正在尝试创建图像浏览器,但是当要加载的图像过多时出现错误

这是我的代码(位图用于第 100 行): http: //pastebin.com/NidnH57b

如果尝试访问包含大量图像的目录,则会出现错误。

是否有加载大量图像的解决方案?

谢谢

4

3 回答 3

1

我会说在活动开始时加载您需要的所有图像不是一个好习惯。例如,Listviews 仅加载将在您的适配器中显示的图像。Yo 应该在 arraylist 中获取您需要的所有信息并使用 arrayAdapter 例如,它将破坏并重新创建所需的视图以节省内存。

一个简单的方法可以在这里找到

于 2013-06-16T10:50:31.800 回答
0

用于MediaStore获取通过文件迭代的所有设备图像非常慢。你可以像这样得到它们:

Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    String[] projection = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA,
            MediaStore.Images.Media.BUCKET_ID };
    String selection = MediaStore.Images.Media.BUCKET_ID + " = " + mAlbumId; //to get from specified folder
    Cursor cursor = getContentResolver().query(uri, projection, selection, null, null);

    while (cursor.moveToNext()) {
        Picture picture = new Picture();
        int columnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
        picture.path = cursor.getString(columnIndex);

        columnIndex = cursor.getColumnIndex(MediaStore.Images.Media._ID);
        picture.id = cursor.getLong(columnIndex);

        columnIndex = cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID);
        picture.bucketId = cursor.getString(columnIndex);

        mAvailableImages.add(picture);
    }
    cursor.close();

然后使用自定义适配器在 ListView 中检索到的数据并编写您自己的 ImageManager,它将为您创建和管理位图。

你可以阅读这个这个主题。

另请查看 Android 原生图库http://viralpatel.net/blogs/pick-image-from-galary-android-app/

于 2013-06-16T10:45:05.033 回答
0

访问目录时不应预加载所有图像。相反,您应该在getView适配器中加载图像(异步)。此外,您可能希望根据图像的分辨率缩小图像,而不是使用inSampleSize. 该站点可能会对您有所帮助:http: //developer.android.com/training/displaying-bitmaps/load-bitmap.html

顺便提一句。您还应该看看ViewHolder-Pattern(例如这里http://www.jmanzano.es/blog/?p=166)。

于 2013-06-16T10:47:44.823 回答