问题
I'm using a Custom s'print DPT100-S thermal printer to made a receipt printing application.
It is able to print graphics using 384 pixels in one line. This data has to be passed on to the printer using 48 bytes (48x8=384). So, each 'bit' represents one dot to be printed (bit will be '0' for white and '1' for black).
So, I need to create a program which will read a monochrome BMP generated in Windows Paint(or any other program) and convert it into this bit format using a C program in Linux.
Please guide me.
回答1:
Pseudo code:
Read BMP
For each row in BMP
For each group of 8 pixels in row
output_byte = 0
For each pixel in current group of 8
output_byte <<= 1 // shift output_byte left by one bit
output_byte |= (pixel != 0) // set rightmost bit in output_byte
// according to input pixel value
Save output_byte in bitmap
回答2:
Take a look at halftoning.
A quick Google will get you references and Java applet like here: http://www.markschulze.net/halftone/index.html
If you don't have to create your own program and you are happy to use off the shelf software, try ImageMagick's convert
command: http://www.imagemagick.org/Usage/quantize/#halftone
e.g.
convert myfile.jpg -colorspace Gray -ordered-dither h4x4a printable-file.bmp
回答3:
This link has a software called LCD assistant which does the same thing as you need. You have to use paint to convert any image to bitmap and then import that bmp image into the software. The output you can choose to be 384 X xyz. You get the output pixels in HEX.
来源:https://stackoverflow.com/questions/8181614/how-to-convert-monochrome-image-to-bitwise-format-for-thermal-printer