(C ++/MFC)如何在Epson打印机上打印图像?

问题描述 投票:0回答:1
I已连接到一个项目,该项目的目标是通过USB或RS232进行编程使用热打印机进行接收输出。我需要使用ESCPOS命令打印收据。 pirnt收据结果→

输入图像描述在这里 我想要recipt→输入图像描述在这里

qr iamage在这里→

输入图像说明此处 此QR图像是位图

{ CString csFileName = fileName; csFileName = csFileName.MakeUpper(); // 1. BMP image load HBITMAP hBmp = (HBITMAP)::LoadImage(NULL, fileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_MONOCHROME); if (hBmp == NULL) return ERR_PRT_WRITE; if (hBmp == NULL) return ERR_PRT_WRITE; CBitmap* pBmp = CBitmap::FromHandle(hBmp); BITMAP bmpInfo; memset(&bmpInfo, 0, sizeof(bmpInfo)); pBmp->GetBitmap(&bmpInfo); if (bmpInfo.bmBitsPixel != 1) { pBmp->DeleteObject(); return ERR_PRT_WRITE; } int pixelWidth = bmpInfo.bmWidth; int height = bmpInfo.bmHeight; int widthBytes = (pixelWidth + 7) / 8; int paddedRowBytes = bmpInfo.bmWidthBytes; int totalPaddedBytes = paddedRowBytes * height; BYTE* paddedData = new BYTE[totalPaddedBytes]; if (pBmp->GetBitmapBits(totalPaddedBytes, paddedData) != totalPaddedBytes) { delete [] paddedData; return ERR_PRT_WRITE; } BYTE* rasterData = new BYTE[widthBytes * height]; for (int row = 0; row < height; row++) { BYTE* src = paddedData + ((height - 1 - row) * paddedRowBytes); BYTE* dst = rasterData + (row * widthBytes); memcpy(dst, src, widthBytes); } delete [] paddedData; const char initPrinter[] = "\x1B\x40"; // ESC @ _printer.write((LPSTR)initPrinter, strlen(initPrinter)); const char pageModeOn[] = "\x1B\x4C"; // ESC L _printer.write((LPSTR)pageModeOn, strlen(pageModeOn)); const char setPageArea[] = { 0x1B, 0x57, // ESC W 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x37, 0x02 }; _printer.write((LPSTR)setPageArea, sizeof(setPageArea)); const char setAbsPosImage[] = { 0x1B, 0x24, 0x00, 0x00 }; // ESC $ _printer.write((LPSTR)setAbsPosImage, sizeof(setAbsPosImage)); BYTE m = 0x01; for (int row = 0; row < height; row++) { BYTE* rowData = rasterData + (row * widthBytes); BYTE nL = (BYTE)(widthBytes & 0xFF); BYTE nH = (BYTE)((widthBytes >> 8) & 0xFF); BYTE escStar[5] = {0x1B, 0x2A, m, nL, nH}; _printer.write((LPSTR)escStar, 5); _printer.write((LPSTR)rowData, widthBytes); } delete [] rasterData; const char setAbsPosText[] = { 0x1B, 0x24, 0xC8, 0x00 }; _printer.write((LPSTR)setAbsPosText, sizeof(setAbsPosText)); char textData[1024]; memset(textData, 0x00, sizeof(textData)); sprintf_s(textData, sizeof(textData), "%s", "Hi hello"); _printer.write(textData, strlen(textData)); _printer.write((LPSTR) "\x1B\x0C", 2); // ESC FF pBmp->DeleteObject(); return TRUE; }
    
c++ mfc escpos
1个回答
0
投票

for (int row = 0; row < height; row+=8) { for (int col=0;col<width; col++) { //make a array to store the row information here BYTE c=0; for (int i=0;i<8;i++) if (IsBitmapPixelBlack(col,row+i)) c|=(1<<i); //Append c to the array } //Print out this row (i.e. these 8 pixels vertically for the the entire width) }

我建议您首先仅获取QR码,然后修理计划,以包括QR码右侧的文本(您需要在第一行之后和第二行之前打印)。 希望这给您一些指导 - 这些东西是非常古老的学校,并且您使用的ESCPOS协议已有1980年底以来已经存在

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.