0

内存不足问题

final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID };
                final String orderBy = MediaStore.Images.Media._ID;
                Cursor imagecursor = managedQuery(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
                        null, orderBy);
                int image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media._ID);
                count = imagecursor.getCount();
                thumbnails = new Bitmap[count];
                arrPath = new String[count];
                thumbnailsselection = new boolean[count];
                for (int i = 0; i < count; i++) {
                    imagecursor.moveToPosition(i);
                    int id = imagecursor.getInt(image_column_index);
                    int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);
                    thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail(
                            getApplicationContext().getContentResolver(), id,
                            MediaStore.Images.Thumbnails.MICRO_KIND, null);
                    arrPath[i]= imagecursor.getString(dataColumnIndex);
                }
                GridView imagegrid = (GridView) findViewById(R.id.PhoneImageGrid);
                imageAdapter = new ImageAdapter();
                imagegrid.setAdapter(imageAdapter);
                imagecursor.close();

在位图上出现内存不足错误:

Bitmap   thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail(
                                getApplicationContext().getContentResolver(), id,
                                MediaStore.Images.Thumbnails.MICRO_KIND, null);

它在某些设备中崩溃请帮助

4

2 回答 2

1

如果您查看 Android 培训手册,有一些文档告诉您如何执行此操作:http: //developer.android.com/training/displaying-bitmaps/cache-bitmap.html

就我个人而言,我会使用Android Universal Image Loader来为您解决这个问题。

于 2013-08-15T20:45:35.360 回答
0

您需要使用compressAndroid 位图类中的方法压缩位图图像。不久前我遇到了这个问题,最终不得不压缩我正在使用的图像..

compress在下面的链接中查看该方法的描述。它应该相当简单。您只需从枚举、“质量”和输出流中选择您的格式。

参考: http: //developer.android.com/reference/android/graphics/Bitmap.html#compress (android.graphics.Bitmap.CompressFormat , int, java.io.OutputStream)

于 2013-08-15T20:43:36.820 回答