title: How to convert binary image to binary array in java?
body: <p>I have a binary image like this:</p>
  
  <p><a href="https://i.stack.imgur.com/56j7em.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/56j7em.jpg" alt="enter image description here"></a></p>
  
  <p>I want to represent or convert this image or (any binary image) in binary array of 0's and 1's then print its values (of course it should be 0's and 1's).</p>
  
  <p>My code prints non-binary values:</p>
  
  <pre><code>import java.io.ByteArrayOutputStream;
  import java.io.File;
  import java.io.IOException;
  import javax.imageio.ImageIO;
  
  public class PP {
  
      public static void main(String argv[]) throws IOException
      {
          File file = new File("binary.jpg");
          BufferedImage originalImage = ImageIO.read(file);
          ByteArrayOutputStream baos=new ByteArrayOutputStream();
          ImageIO.write(originalImage, "jpg", baos);
          byte[] imageInByte = baos.toByteArray();
  
          for(int i = 0; i &lt; imageInByte.length; i++)
          {
              System.out.println(imageInByte[i]);
          }
      }
  }
  </code></pre>