如何将大视图转换为位图?

时间:2018-02-23 11:29:57

标签: android android-canvas android-bitmap

我需要将大视图(宽度和高度为1920x840)转换为位图。我在内存大小较小的低端设备上遇到 java.lang.OutOfMemoryError 异常。我试过这段代码。

        setDrawingCacheEnabled(true);
        buildDrawingCache();
        Bitmap b = getDrawingCache();
        if (b == null) {
            int width = getLayoutParams().width;
            int height = getLayoutParams().height;
            //here i am getting out of memory exception
            b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            Canvas c = new Canvas(b);
            draw(c);
        }

        destroyDrawingCache();
        setDrawingCacheEnabled(false); 
        return b;

0 个答案:

没有答案