Forráskód Böngészése

调试打印图片的问题

张洋 6 éve
szülő
commit
f6b250713d

+ 90 - 0
lewaimai_pos_windows/tool/CPosPrinter.cpp

@@ -882,6 +882,8 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
 			POS_TextOut("请使用配送员app扫码绑定订单", false, false, 1);
 		}
 
+		POS_OutBmp(_T("D:\\256.jpg"));
+
         //走纸几行再切
         POS_FeedLine();
         POS_FeedLine();
@@ -1733,6 +1735,94 @@ void CPosPrinter::POS_OutBmp(std::wstring ImagePath)
 	WriteBuf(data3, 2);
 }
 
+/*
+ *这个是8点双密度的模式
+ **/
+void CPosPrinter::POS_OutBmp_New(std::wstring ImagePath)
+{
+	//设置行间距为0
+	unsigned char data[3] = { 0x1B, 0x33, 0x00 };
+	WriteBuf(data, 3);
+
+	//设置图像居中对齐
+	unsigned char data2[3] = { 0x1B, 0x61, 0x01 };
+	WriteBuf(data2, 3);
+
+	CBitmapHelper helper;
+	helper.LoadImage(ImagePath.c_str());
+
+	Bitmap* bmp = helper.getBmp();
+
+	//先进行图片预处理
+	unsigned int nWidth = bmp->GetWidth();
+	unsigned int nHeight = bmp->GetHeight();
+
+	//压缩尺寸
+	if (nWidth > 380)
+	{
+		int newWidth = 380;
+		int newHeight = (int)(nHeight / (nWidth / 380.0));
+
+		helper.ScaleBitmap(newWidth, newHeight);;
+
+		nWidth = newWidth;
+		nHeight = newHeight;
+	}
+
+	//二值化
+	helper.Image2Values();
+
+	//获得最新的图像指针
+	bmp = helper.getBmp();
+
+	//选择位图模式
+	unsigned char escBmp[5] = { 0x1B, 0x2A, 0x01, 0x00, 0x00 };
+
+	escBmp[3] = (unsigned char)(nWidth % 256);
+	escBmp[4] = (unsigned char)(nWidth / 256);
+
+	Gdiplus::Color pixelColor;
+
+	unsigned char *dataTmp = new unsigned char[1];
+	dataTmp[0] = (unsigned char)'\x00';
+
+	//循环图片像素打印图片
+	for (unsigned int i = 0; i < (nHeight / 8 + 1); i++)
+	{
+		//设置模式为位图模式
+		WriteBuf(escBmp, 5);
+
+		//循环宽
+		for (unsigned int j = 0; j < nWidth; j++)
+		{
+			for (unsigned int k = 0; k < 8; k++)
+			{
+				//找到有像素的区域,也就是未超出位图高度的区域
+				if (((i * 8) + k) < nHeight)
+				{
+					bmp->GetPixel(j, (i * 8) + k, &pixelColor);
+					unsigned char r = pixelColor.GetR();
+
+					if (r == 0)
+					{
+						//如果本来是黑色的像素,那么就把对应的数据位设置为1
+						dataTmp[0] += (unsigned char)(128 >> (k % 8));
+					}
+				}
+			}
+
+			WriteBuf(dataTmp, 1);
+			dataTmp[0] = (unsigned char)'\x00';
+		}
+	}
+
+	delete[] dataTmp;
+
+	//还原默认的行间距
+	unsigned char data3[2] = { 0x1B, 0x32 };
+	WriteBuf(data3, 2);
+}
+
 void CPosPrinter::BIAOQIAN_Reset()
 {
     char endTag[3] = {0x0d, 0x0a, 0x00};

+ 1 - 0
lewaimai_pos_windows/tool/CPosPrinter.h

@@ -70,6 +70,7 @@ private:
 	int POS_CutPaper();
 	void POS_OutQRCode(std::string dataString);
 	void POS_OutBmp(std::wstring ImagePath);
+	void POS_OutBmp_New(std::wstring ImagePath);
 
 	//标签打印机的处理方法
 	void BIAOQIAN_Reset();