0

我从图库中选择 700kb 图像并收到 IllegalArgumentException。我将其与使用联系起来recycle()以节省一些内存。当我开始出现 OutOfMemoryError 时,它变成了实际问题,所以我认为我必须使用回收。我是否以错误的方式调用它或者有一些规则如何使用它?

错误:

07-02 10:25:27.466: E/AndroidRuntime(2422): FATAL EXCEPTION: main
07-02 10:25:27.466: E/AndroidRuntime(2422): java.lang.IllegalArgumentException: Cannot draw recycled bitmaps
07-02 10:25:27.466: E/AndroidRuntime(2422):     at android.view.GLES20Canvas.drawBitmap(GLES20Canvas.java:778)
07-02 10:25:27.466: E/AndroidRuntime(2422):     at android.view.GLES20RecordingCanvas.drawBitmap(GLES20RecordingCanvas.java:117)

称呼:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(
intent, "Select Picture"), 31);

结果:

if (requestCode == 31 && resultCode == RESULT_OK && null != data) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };

            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();
            Bitmap bitmap = BitmapFactory.decodeFile(picturePath);
            pho1.setImageBitmap(bitmap);
            // ImageView imageView = (ImageView) findViewById(R.id.imgView);
            // imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
            //

            // Bitmap bitmap = (Bitmap) data.getExtras().get("data");
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream);
            byte[] byte_arr = stream.toByteArray();

            photo1 = Base64.encodeToString(byte_arr, Base64.DEFAULT);
            bitmap.recycle();
            bitmap = null;
            byte_arr=null;

            try {
                stream.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
4

1 回答 1

0

请删除 bitmap.recycle(); 陈述。

于 2013-07-02T12:48:24.460 回答