0

I have a 1bpp monochrome bitmap image loaded into memory. I have the image data loaded into a byte array. I am trying to print to a Zebra printer and following their manual I feel I mostly have the code working except that when I convert the image data into hexcode and send the command to the printer, the bounding box appears to print the correct size, but the image is hopelessly scrambled.

I suspect that this is because the following method that I found on StackOverflow for converting a byte array into hex is reading each byte value in Big Endian order when I need it to look at it in Little Endian order.

public static String bytesToHex(byte[] b) {
    char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7',
            '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
    StringBuffer buf = new StringBuffer();
    for (int j=0; j<b.length; j++) {

        buf.append(hexDigit[b[j] & 0x0f]);
        buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
    }
    return buf.toString().toUpperCase();
}

At this point I am stuck. Does anybody have any suggestions how I can modify the above the code to read each byte value in the proper order for reading bitmap image data?

EDIT:

The image, it is James Bond mangled with a poor ad-hoc Floyd-Steinberg dithering implementation (thats a different problem altogether)...

enter image description here

EDIT 2:

Well that didn't work, it looks like when I upload it then it gets converted to PNG.

Bitmap data in Hex:

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 FF FF FF 00 00 00 FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 FF FF FF 00 00 00 FF FF FE 00 00 ...

Hmmmm... I thought Monochrome 1bpp bitmaps only had two possible colors? Why did image4j ConvertUtil.convert1 introduce other colors? I wonder if this is the problem?

EDIT 3:

NVM, each bit determines the color in 1bpp, so each byte can represent up to 8 pixels. This is likely correct.

Community
  • 1
  • 1
maple_shaft
  • 10,435
  • 6
  • 46
  • 74
  • I'd be surprised if the problem is nibble order. Are the images available? – trashgod Nov 09 '12 at 20:33
  • @trashgod Just to be certain I dumped the bytes for the monochrome 1bpp data to disk to verify and sure enough it is well formatted – maple_shaft Nov 09 '12 at 20:34
  • @trashgod I posted some more information and a hex output of the bitmap data. I think your right, maybe the nibble order isn't the problem – maple_shaft Nov 09 '12 at 20:46
  • Another factor to check is the [image stride](http://stackoverflow.com/q/2004602/230513); 31 bytes * 8 bits/byte = 248 bits in your example. Is that right? – trashgod Nov 10 '12 at 03:35

0 Answers0