gpt4 book ai didi

java - Bitmap.createBitmap(int, int, Bitmap.Config) 在类膨胀期间抛出运行时异常

转载 作者:行者123 更新时间:2023-11-30 11:52:56 25 4
gpt4 key购买 nike

我正在尝试在 Android 中扩展可缩放的图像查看器以并排使用两个图像。为此,我使用了 Bitmap.createBitmap(int, int, Bitmap.Config)。不幸的是,这似乎会使 VM 崩溃。

代码是

    protected void combineBitmaps() {
image0Width = bitmap0.getWidth();
image0Height = bitmap0.getHeight();
image1Width = bitmap1.getWidth();
image1Height = bitmap1.getHeight();

//These methods just get correct values for image[0|1][Width|Height].
int width = getCanvasWidth();
int height = getCanvasHeight();

//THIS LINE CRASHES
Bitmap bitmap_tmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

bitmap = bitmap_tmp;

Canvas combination = new Canvas(bitmap);

combination.drawBitmap(bitmap0, 0f, getImage0VertOffset(), null);
combination.drawBitmap(bitmap1, image0Width, getImage1VertOffset(), null);
}

我从 getCanvasWidth() 得到的值是 2464,从 getCanvasHeight() 得到的值是 2048。我得到的异常是

Unable to start activity ComponentInfo{com.tse.scview/com.tse.scview.ScalableViewWrapper}: android.view.InflateException: Binary XML file line #8: Error inflating class com.tse.scview.ScalableFacingPageView

其中 com.tse.scview.ScalableFacingPageView 是我们正在构造的类(构造函数调用此函数)。

我已经从这一行中分离出所有内容——将位图分配给类位图、获取宽度和高度函数等——以确定它实际上是 Bitmap.createBitmap 导致了问题。不幸的是,我无法弄清楚问题出在哪里。

更新:作为健全性检查,我为宽度和高度设置了较小的值(12 和 13 ... 为什么不呢)。现在可以了。所以这是一个 RAM 问题,这对我们来说是一个痛苦,但有效地回答了这个问题。

最佳答案

如果我正确阅读您的代码并提出问题,则位图为 2464 x 2048 x 4 字节。那是 16 兆字节。您正在创建其中两个。那是 32 兆字节。

关于java - Bitmap.createBitmap(int, int, Bitmap.Config) 在类膨胀期间抛出运行时异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6570733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com