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)...
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.