How to convert image black and white image to 0 - 1 byte array in android
<p>I'm trying to convert an <code>.BMP</code> pic into <code>byte[]</code> or <code>byte[][]</code>. I already try 2 solutions and i get strange results </p>

<p>First : </p>

<pre><code>Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.qr);
int bytes = bitmap.getByteCount();
ByteBuffer buffer = ByteBuffer.allocate(bytes);
bitmap.copyPixelsToBuffer(buffer);
byte[] byt = buffer.array();
</code></pre>

<p>In the <code>byt</code> i get array with over 36 000 element and all have <code>-1</code> value.</p>

<p>My second try was : </p>

<pre><code>Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.qr);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100,stream);
byte[] byteArrat = stream.toByteArray();
</code></pre>

<p>But now i have array with over 1200 elements which look random ( value form -180 to 100 ) </p>

<p>Is there any possible to mage bmp to array which have 0 for <code>WHITE</code> color and 1 for <code>BLACK</code> ? Already i'm stock and don't know what to do. The pic : </p>

<p><a href="https://i.stack.imgur.com/Z7Lgh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z7Lgh.png" alt="Image to decode"></a></p>