Android的错误java.lang.OutOfMemoryError:位图大小超过VM预算 [英] Android Error java.lang.OutOfMemoryError: bitmap size exceeds VM budget

查看:105
本文介绍了Android的错误java.lang.OutOfMemoryError:位图大小超过VM预算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到异常错误从资产ArrayList中加载图像时。 这是在日志猫错误:   E / AndroidRuntime(2837):java.lang.OutOfMemoryError:位图大小超过VM预算

Am getting Exception error when loading images from assets to arraylist. this is the error in log cat: E/AndroidRuntime(2837): java.lang.OutOfMemoryError: bitmap size exceeds VM budget

请有人帮我这个,在此先感谢

Please some one help me with this,Thanks in advance

推荐答案

有一次,我试图重新大小的图像,我也有同样的问题,我用下面的code,你可以修改它你的,

Once, i tried to re-size the image, i' also having the same problem, i used the below code, you can modify as it yours,

public Bitmap custom_SizedImage(String intent_data2) {

        Options options = new Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(intent_data2, options);
        double sampleSize = 0;
        Boolean scaleByHeight = Math.abs(options.outHeight - targetHeight) >= Math
                .abs(options.outWidth - targetWidth);

        if (options.outHeight * options.outWidth * 2 >= 1638) {
            sampleSize = scaleByHeight ? options.outHeight / targetHeight
                    : options.outWidth / targetWidth;
            sampleSize = (int) Math.pow(2d,
                    Math.floor(Math.log(sampleSize) / Math.log(2d)));
        }
        options.inJustDecodeBounds = false;
        options.inTempStorage = new byte[128];
        while (true) {
            try {
                options.inSampleSize = (int) sampleSize;
                           // here you can do you Decode process
                //mBitmap = BitmapFactory.decodeFile(intent_data2, options);

                break;
            } catch (Exception ex) {
                try {
                    sampleSize = sampleSize * 2;
                } catch (Exception ex1) {

                }
            }
        }
        return scaledBitmap;

    }

这篇关于Android的错误java.lang.OutOfMemoryError:位图大小超过VM预算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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