gpt4 book ai didi

android - 不可变位图崩溃错误

转载 作者:IT老高 更新时间:2023-10-28 13:16:56 25 4
gpt4 key购买 nike

java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor
at android.graphics.Canvas.<init>(Canvas.java:127)
at app.test.canvas.StartActivity.applyFrame(StartActivity.java:214)
at app.test.canvas.StartActivity$1.onClick(StartActivity.java:163)
at android.view.View.performClick(View.java:4223)
at android.view.View$PerformClick.run(View.java:17275)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)

我从开发者控制台收到这个崩溃错误..我不明白是什么问题..

    BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inScaled = true;
opt.inPurgeable = true;
opt.inInputShareable = true;
Bitmap brightBitmap = BitmapFactory.decodeResource(getResources(), position, opt);
brightBitmap = Bitmap.createScaledBitmap(brightBitmap, 550, 550, false);
chosenFrame = brightBitmap;
Bitmap workingBitmap = Bitmap.createBitmap(chosenFrame);
workingBitmap = Bitmap.createBitmap(workingBitmap);
Canvas c = new Canvas(workingBitmap);

我觉得和这个有关?

最佳答案

您必须将 workingBitmap 转换为 Mutable Bitmap 才能在 Canvas 上绘图。 (注意:这种方法不利于节省内存,会占用额外的内存)

Bitmap workingBitmap = Bitmap.createBitmap(chosenFrame);
Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(mutableBitmap);

这个答案有助于不要浪费内存 Convert immutable bitmap to a mutable bitmap

关于android - 不可变位图崩溃错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13119582/

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