0

I have a 262144(512*512) one dimensional pixel int[] pixelsArray array taht I want to convert into Bitmap and display it in an Android app, so I put

 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)

I tried some SO solutions, but none worked. Could someone help ?

epsilones
  • 11,279
  • 21
  • 61
  • 85
  • what error did you get ? – Blackbelt Oct 08 '15 at 07:38
  • @Blackbelt sorry error when copy pasting. Here's the log – epsilones Oct 08 '15 at 07:41
  • please check this topic carefully ( the same issue ). http://stackoverflow.com/questions/9370145/mysterious-stacktrace-in-android-developer-console-bitmap-size-exceeds-32bits –  Oct 08 '15 at 07:50
  • @Tokiroto yes I have already looked at it - but it is not my problem since I need to create a bitmap from a pixel array and not from a path – epsilones Oct 08 '15 at 07:58

1 Answers1

1

here's the answer that worked :

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);
epsilones
  • 11,279
  • 21
  • 61
  • 85