位图内存不足的错误在安卓... [英] Bitmap out of memory error in android...

查看:139
本文介绍了位图内存不足的错误在安卓...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作在一个Android应用程序,我使用的是位图图像绑定到ImageView的。我的要求是旋转的ImageView的,给予边境的ImageView的。我已经成功地实现这一点,但使用这个活动出现两三次强制关闭的错误说法位图出来的虚拟机内存的应用程序后。请帮我减少了位图内存消耗在我的code。让我知道如何修改$ C $下一样的吗?

 最终诠释BORDER_WIDTH = 5;
        //设置边框颜色
        最终诠释BORDER_COLOR = Color.WHITE;
        位图资源= Bitmap.createBitmap(CAPTURE_IMAGE.getWidth()+ 2
                * BORDER_WIDTH,CAPTURE_IMAGE.getHeight()+ 2 * BORDER_WIDTH,
                CAPTURE_IMAGE.getConfig());
        System.gc()的;
        帆布油画=新的Canvas(RES);
        涂料粉刷=新的油漆();
        paint.setColor(BORDER_COLOR);
        canvas.drawRect(0,0,res.getWidth(),res.getHeight(),漆);

        canvas.drawBitmap(CAPTURE_IMAGE,BORDER_WIDTH,BORDER_WIDTH,油漆);
        矩阵垫=新的Matrix();
        //设置ImageView的位置
        mat.postRotate(355);

        bMapRotate = Bitmap.createBitmap(水库,0,0,res.getWidth(),
                res.getHeight(),垫,真正的);
        System.gc()的;
        res.recycle();
        RES = NULL;
        油漆= NULL;
        帆布= NULL;
        垫= NULL;
        //设置捕获的位图图像中的ImageView
        mShareImageView.setImageBitmap(bMapRotate);
 

解决方案

在mainfest文件中添加--->机器人:largeHeap:真正的

I am working in an android application and I am using a bitmap to bind an image to an ImageView. My requirement is to rotate that ImageView and give a border to that ImageView. I have successfully implemented this, but after the application uses this activity two-three times a "force close" error appears saying Bitmap out of VM memory. Please help me to minimize the bitmap memory consumption in my code. And let me know how to modify the code for the same?

final int BORDER_WIDTH = 5;
        // Set the border color
        final int BORDER_COLOR = Color.WHITE;
        Bitmap res = Bitmap.createBitmap(CAPTURE_IMAGE.getWidth() + 2
                * BORDER_WIDTH, CAPTURE_IMAGE.getHeight() + 2 * BORDER_WIDTH,
                CAPTURE_IMAGE.getConfig());
        System.gc();
        Canvas canvas = new Canvas(res);
        Paint paint = new Paint();
        paint.setColor(BORDER_COLOR);
        canvas.drawRect(0, 0, res.getWidth(), res.getHeight(), paint);

        canvas.drawBitmap(CAPTURE_IMAGE, BORDER_WIDTH, BORDER_WIDTH, paint);
        Matrix mat = new Matrix();
        // Set the Imageview position
        mat.postRotate(355);

        bMapRotate = Bitmap.createBitmap(res, 0, 0, res.getWidth(),
                res.getHeight(), mat, true);
        System.gc();
        res.recycle();
        res = null;
        paint = null;
        canvas = null;
        mat = null;
        // Set the captured bitmap image in the imageview
        mShareImageView.setImageBitmap(bMapRotate);

解决方案

in mainfest file add ---> android:largeHeap:"true"

这篇关于位图内存不足的错误在安卓...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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