I have a binary image like this:
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).
My code prints non-binary values:
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 < imageInByte.length; i++)
{
System.out.println(imageInByte[i]);
}
}
}