gpt4 book ai didi

java - Android 中转换位图中的像素数组

转载 作者:行者123 更新时间:2023-12-01 11:05:26 24 4
gpt4 key购买 nike

我有一个 262144(512*512) 一维像素 int[]pixelsArray 数组,我想将其转换为 Bitmap 并显示它在 Android 应用程序中,所以我把

 bitmap = Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixelsArray, 0, 512, 0, 0, 512, 512);

I get this message

java.lang.IllegalArgumentException: bitmap size exceeds 32bits
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: bitmap size exceeds 32bits
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:689)
at android.graphics.Bitmap.createBitmap(Bitmap.java:666)
at android.graphics.Bitmap.createBitmap(Bitmap.java:633)

我尝试了一些SO解决方案,但没有一个有效。有人可以帮忙吗?

最佳答案

这是有效的答案:

bitmap = Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888);
byte[] byteArray = new String(pixelsArray).getBytes("UTF-8");
BitmapFactory.Options thumbOpts = new BitmapFactory.Options();
thumbOpts.inSampleSize = 4;
bitmap = BitmapFactory.decodeByteArray(byteArray, 0, pixelsArray.length, thumbOpts);

关于java - Android 中转换位图中的像素数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33009468/

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