How to convert monochrome image to bitwise format

2019-04-11 02:27发布

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.

3条回答
一纸荒年 Trace。
2楼-- · 2019-04-11 02:31

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
查看更多
孤傲高冷的网名
3楼-- · 2019-04-11 02:35

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.

查看更多
姐就是有狂的资本
4楼-- · 2019-04-11 02:47

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
查看更多
登录 后发表回答