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

onResult:

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