I have a byte array with series of 0 and -1 (255). It’s a result of binarization using the Otsu algorithm. I used:
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inDither = true;
opt.inPreferredConfig = Bitmap.Config.RGB_565; // I have tried ARGB_8888 aswell
Bitmap out = BitmapFactory.decodeByteArray(data, 0, data.length, opt);
Unfortunately, it returns null. Just like the other questions regarding BitmapFactory.decodeByteArray().
I have tested other methods like nested for loops, it works but it takes too long to process, especially for large images.
This is what I currently use to generate the binarized data:
ptr = 0;
while (ptr < srcData.length)
{
monoData[ptr] = ((0xFF & srcData[ptr]) >= threshold) ? (byte) 255 : 0;
ptr ++;
}
I hope you can lead me to a better way on solving this issue. Thanks!
565 is a representation that uses 2 bytes per pixel.
Moreover, decodeByteArray is a method that reads a compressed byte[] (see documentation).
Here is what I would do :
monoData[ptr] = ((0xFF & srcData[ptr]) >= threshold) ? 0xffffffff : 0xff000000;
nota : one thing that could have helped you : decodeByteArray has no idea of the geometry of your image, hence can of course not decode it to what you are expected.