Gprinter Raster Bitmap lattice data parsing tool

Source: Internet
Author: User

Recently involved in the project has a need to parse the raster bitmap data of the best thermal printer and save it as a picture file. The data is crawled through the bus hound, as shown in.

Where 1b 40 is the initialization of the printer instructions, the corresponding ASCII code is ESC @,1b 4a 18 for printing and paper instructions, the corresponding ASCII code is ESC j,1d 76 30 is the instruction of the print raster bitmap, the corresponding ASCII code is GS v 0, followed by the raster bitmap mode (0x00 ), horizontal bitmap bytes (0x0036), and vertical bitmap points (0x0018), followed by the bitmap data for this frame (0x36*0x18=1296 bytes). The data file is followed by a 1b 4a 18 print-out frame and a 1d 76 30 bitmap data frame that repeats until the end of the print content.

Data parsing is a key link, and it is necessary to consider lossless compression of raster bitmap data and evaluate the compression efficiency. In order to visually display the parsed image and related information, and save the image in BMP and PNG format, based on MFC wrote a gadget, the interface as shown.

The white area on the left side of the window shows the parsed image, the right side displays information about the original data and the resulting zip package, bitmap, and PNG images. In order to facilitate debugging, data files support through the bus hound crawl of the TXT, the original raster bitmap lattice data, and their zip package, simply drag the file to the inside of the window to complete the parsing. When bitmap is generated, the direction of the scan is supported, and the binary file (Plain binary) that generates the raw data is selected, the binary file of the raw data is compressed, and the pure data file that rejects the ESC instruction from the original data.

The image and related information after parsing the lattice data are shown.

When you save raster bitmap lattice data as bitmap, it is important to note that if the bitmap bytes in the horizontal direction are not integral multiples of 4, you need to expand to a full multiple of 4. In this example, the original width is 54 bytes, which needs to be expanded to 56 bytes, and the expanded pixel width is 448 (56*8). In addition, the original raster bitmap lattice data is arranged from top to bottom (Top-down), if bitmap is generated when the same scan is selected, the biheight in the bitmapinfoheader struct should be negative, and the general bitmap file is the bottom-up scan ( bottom-up), and the original data is arranged in the opposite direction, at which point the biheight is positive. You can see that the data after the zip compression is about 1/5 of the original size. The PNG image size is also about 1/5 of BMP, but compared to the beyond compare tool, the image does not have any loss, as shown in.

This task is basically completed and achieved the desired results. The first contact with the thermal printer, there is a preliminary understanding, there is time to consider this thing in turn, that is, to convert any image file into raster bitmap lattice data, so that you can print two-dimensional code or other complex images.

Gprinter Raster Bitmap lattice data parsing tool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.