1

I am trying to print bitmap image. In order to print image my printer needs byte array of bitmap. Picture size is 128x128 pixel.

Here is code how I read and convert image to byte array.

BufferedImage image = ImageIO.read(new File("test.bmp"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "bmp", baos);
byte[] imageInByte = baos.toByteArray();
System.out.println(imageInByte.length);

After code execution imageInByte array length is 2110. What am I missing here? Should not array length be 16384 (128 x 128)?

1 Answer 1

1

You are assuming one byte per pixel and no header information. The "bitsPerPixel" header will play a large part in determining how much space the image data takes up. See the structure of a bitmap file here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.