图像处理:" dalvikvm:外部分配太大,此过程"错误 [英] Image Processing: "dalvikvm: external allocation too large for this process" error

查看:102
本文介绍了图像处理:" dalvikvm:外部分配太大,此过程"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个照片编辑应用程序。当我导入图像,它工作正常,但是,开辟编辑导致其崩溃的形象。

I have a photo editing app. When I import an image, it works fine but, opening up the image for editing causes it to crash.

这是logcat的输出:

This is the logcat output:


08-04 20:56:16.973: E/dalvikvm-heap(336): 810000-byte external allocation too large for this process.
08-04 20:56:17.073: I/dalvikvm-heap(336): Clamp target GC heap from 25.289MB to 24.000MB
08-04 20:56:17.073: E/GraphicsJNI(336): VM won't let us allocate 810000 bytes

更新::

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RESULT_LOAD_IMAGE && 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();

        ImageView imageView = (ImageView) findViewById(R.id.ivPhoto);
        chosenBitmap = superDecodeFile(new File(picturePath));
        imageView.setBackgroundColor(0);
        Bitmap bMap =   Bitmap.createScaledBitmap(chosenBitmap, 500, 500, true);
        imageView.setImageBitmap(bMap);
    }

}

这是我的onResult code ..等等的ImageView的choosenBitmap显示器(ivPhoto) 我需要使用.recycle(); 所以我腾出通过回收已经ImageView的一些内存.. 我在哪里使用.recycle(); ? 我试图改变.setBackgroundColor(0);回收();但它不工作

this is my onResult code .. so the choosenBitmap displays on the imageView ( ivPhoto ) I need to use .recycle(); so i free up some memory by recycling the already imageView .. where do I use the .recycle(); ? I tried to change the .setBackgroundColor(0); to .recycle(); but it doesn't work

推荐答案

这是一个内存泄漏错误。

This is a memory leak error.

您的应用程序分配的大小〜24MB的堆。但是,您要编辑的图像比堆大小。

Your app is allocated a heap of size ~24MB. But the image you are trying to edit is larger than the heap size.

这是发生,因为你没有释放内存。 Android的Dalvik虚拟机不小心 GC 的-ing使用的应用程序的本地内存。所以,当在Android的图像时,则需要明确使用循环()。这样就减少了本机内存。

This is happening because you are not freeing up the memory. Android's Dalvik VM does not take care of GC-ing the native memory used by the app. So, when dealing with images in Android, you need to explicitly use recycle(). This frees up the native memory.

有关更多deatils:<一href="http://stackoverflow.com/questions/2191407/changing-imageview-content-causes-outofmemoryerror">Changing ImageView的内容导致的OutOfMemoryError

For more deatils: Changing ImageView content causes OutOfMemoryError

这篇关于图像处理:&QUOT; dalvikvm:外部分配太大,此过程&QUOT;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆