张洋 6 лет назад
Родитель
Сommit
ed05de687b

+ 111 - 0
lewaimai_pos_windows/helper/CBitmapHelper.cpp

@@ -0,0 +1,111 @@
+#include "../pch/pch.h"
+#include "CBitmapHelper.h"
+
+
+CBitmapHelper::CBitmapHelper()
+{
+}
+
+
+CBitmapHelper::~CBitmapHelper()
+{
+    if(m_bmp != NULL)
+    {
+        delete m_bmp;
+    }
+}
+
+void CBitmapHelper::LockBitmap(Gdiplus::Bitmap *bmp, BitmapData *data)
+{
+    Gdiplus::Rect r(0, 0, bmp->GetWidth(), bmp->GetHeight());
+    bmp->LockBits(&r, ImageLockModeRead | ImageLockModeWrite,
+                  PixelFormat32bppARGB, data);
+}
+
+void CBitmapHelper::UnlockBitmap(Gdiplus::Bitmap *bmp, BitmapData *data)
+{
+    bmp->UnlockBits(data);
+}
+
+void CBitmapHelper::Gray(BitmapData *data)
+{
+    PARGBQuad p = (PARGBQuad)data->Scan0;
+    INT offset = data->Stride - data->Width * sizeof(ARGBQuad);
+
+    for(UINT y = 0; y < data->Height; y++, p = (PARGBQuad)((BYTE*)p + offset))
+    {
+        for(UINT x = 0; x < data->Width; x++, p++)
+            p->Blue = p->Green = p->Red =
+                                     (UINT)(p->Blue * 29 + p->Green * 150 + p->Red * 77 + 128) >> 8;
+
+    }
+}
+
+void CBitmapHelper::GrayAnd2Values(BitmapData *data)
+{
+    PARGBQuad p = (PARGBQuad)data->Scan0;
+    INT offset = data->Stride - data->Width * sizeof(ARGBQuad);
+
+    for(UINT y = 0; y < data->Height; y++, p = (PARGBQuad)((BYTE*)p + offset))
+    {
+        for(UINT x = 0; x < data->Width; x++, p++)
+        {
+            if(((p->Blue * 29 + p->Green * 150 + p->Red * 77 + 128) >> 8) < m_threshold)
+            {
+                //灰度值不够,就变为黑色
+                p->Color &= 0xff000000;
+            }
+            else
+            {
+                //灰度值高,就是白色
+                p->Color |= 0x00ffffff;
+            }
+        }
+    }
+}
+
+/*
+ *加载一张图片,并保存为二值图的格式
+ **/
+void CBitmapHelper::Image2Values()
+{
+    BitmapData data;
+    LockBitmap(m_bmp, &data);
+
+    GrayAnd2Values(&data);
+
+    UnlockBitmap(m_bmp, &data);
+}
+
+Gdiplus::Bitmap* CBitmapHelper::getBmp()
+{
+    return m_bmp;
+}
+
+void CBitmapHelper::ScaleBitmap(UINT nWidth, UINT nHeight)
+{
+    Bitmap * pTemp = new Bitmap(nWidth, nHeight, m_bmp->GetPixelFormat());
+
+    if(pTemp)
+    {
+        Graphics * g = Graphics::FromImage(pTemp);
+
+        if(g)
+        {
+            g->SetInterpolationMode(InterpolationModeHighQualityBicubic);
+
+            g->DrawImage(m_bmp, 0, 0, nWidth, nHeight);
+
+            delete g;
+        }
+    }
+
+    delete m_bmp;
+
+    m_bmp = pTemp;
+}
+
+void CBitmapHelper::LoadImage(std::wstring wsPath)
+{
+	m_bmp = new Gdiplus::Bitmap(wsPath.c_str());
+}

+ 46 - 0
lewaimai_pos_windows/helper/CBitmapHelper.h

@@ -0,0 +1,46 @@
+#pragma once
+
+#include "../pch/pch.h"
+
+typedef union
+{
+    ARGB Color;
+    struct
+    {
+        BYTE Blue;
+        BYTE Green;
+        BYTE Red;
+        BYTE Alpha;
+    };
+} ARGBQuad, *PARGBQuad;
+
+class CBitmapHelper
+{
+public:
+	CBitmapHelper();
+	~CBitmapHelper();
+
+	void LockBitmap(Gdiplus::Bitmap *bmp, BitmapData *data);
+
+	void UnlockBitmap(Gdiplus::Bitmap *bmp, BitmapData *data);
+
+	//ת³É»Ò¶Èͼ
+	void Gray(BitmapData *data);
+
+	//ת³É¶þֵͼ
+	void GrayAnd2Values(BitmapData *data);
+
+	void Image2Values();
+
+	Gdiplus::Bitmap* getBmp();
+
+	void ScaleBitmap(UINT nWidth, UINT nHeight);
+
+	void LoadImage(std::wstring wsPath);
+
+private:
+    Gdiplus::Bitmap* m_bmp = NULL;
+
+    int m_threshold = 128;
+};
+

+ 2 - 0
lewaimai_pos_windows/lewaimai_pos_windows.vcxproj

@@ -228,6 +228,7 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClInclude Include="helper\CBitmapHelper.h" />
     <ClInclude Include="tool\CComHelper.h" />
     <ClInclude Include="wnd\CMessageboxWnd.h" />
     <ClInclude Include="wnd\CUpdateWnd.h" />
@@ -259,6 +260,7 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     <ClInclude Include="control\OrderListUI.h" />
   </ItemGroup>
   <ItemGroup>
+    <ClCompile Include="helper\CBitmapHelper.cpp" />
     <ClCompile Include="tool\CComHelper.cpp" />
     <ClCompile Include="wnd\CMessageboxWnd.cpp" />
     <ClCompile Include="wnd\CUpdateWnd.cpp" />

+ 6 - 0
lewaimai_pos_windows/lewaimai_pos_windows.vcxproj.filters

@@ -102,6 +102,9 @@
     <ClInclude Include="tool\CComHelper.h">
       <Filter>头文件</Filter>
     </ClInclude>
+    <ClInclude Include="helper\CBitmapHelper.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="pch\pch.cpp">
@@ -182,6 +185,9 @@
     <ClCompile Include="tool\CComHelper.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
+    <ClCompile Include="helper\CBitmapHelper.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <Image Include="resource\lewaimai.ico">

+ 13 - 26
lewaimai_pos_windows/pch/pch.h

@@ -1,11 +1,4 @@
-// 入门提示: 
-//   1. 使用解决方案资源管理器窗口添加/管理文件
-//   2. 使用团队资源管理器窗口连接到源代码管理
-//   3. 使用输出窗口查看生成输出和其他消息
-//   4. 使用错误列表窗口查看错误
-//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
-//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
-
+
 #ifndef PCH_H
 #define PCH_H
 
@@ -34,36 +27,32 @@
 
 using namespace std;
 
-/*
- *boost库的头文件
- **/
+//boost库的头文件
 #include <boost/asio.hpp>
 #include <boost/bind.hpp>
 
-/*
- *操作系统相关的头文件
- **/
-#ifdef _WIN32
+using boost::asio::ip::tcp;
+
+//windows库
 #include <windows.h>
 #include <io.h>
 #include <ShellAPI.h>
-#else
-#include <unistd.h>
-#include <sys/sysinfo.h>
-#endif
-
 #include <atltypes.h>
 #include <objbase.h>
 #include <zmouse.h>
 #include <exdisp.h>
 #include <comdef.h>
+#include <winioctl.h>
+#include <setupapi.h>
 
- /*
-  *UI库用到的一些东西
-  **/
+//UI库
 #include <DuiLib/UIlib.h>
 using namespace DuiLib;
 
+//gdi+
+#include <gdiplus.h>
+using namespace Gdiplus;
+
 //资源文件
 #include "../resource/resource.h"
 
@@ -75,9 +64,7 @@ using namespace DuiLib;
 
 using namespace rapidjson;
 
-/*
- *常用的辅助函数
- **/
+//自己写的辅助函数
 #include "../helper/define.h"
 #include "../helper/CRandomHelper.h"
 #include "../helper/CSystem.h"

+ 64 - 235
lewaimai_pos_windows/tool/CPosPrinter.cpp

@@ -1,12 +1,8 @@
 #include "../pch/pch.h"
 #include "CPosPrinter.h"
 
-#include <winioctl.h>
-#include <setupapi.h>
-
 #include "../tool/CComHelper.h"
-
-using boost::asio::ip::tcp;
+#include "../helper/CBitmapHelper.h"
 
 CPosPrinter::CPosPrinter(): m_socket(m_io)
 {
@@ -17,6 +13,10 @@ CPosPrinter::~CPosPrinter()
 {
 }
 
+/*
+ *usbType是1表示只查找收银小票打印机,会排除已知的标签打印机
+ *usbType为2表示所有usb打印机都查找,包含标签与非标签
+ **/
 void CPosPrinter::InitUsb(int usbType)
 {
     //设置中文字符
@@ -33,7 +33,7 @@ void CPosPrinter::InitUsb(int usbType)
     {
         LOG_INFO("准备打开端口 Port = " << m_usb_devices[i].c_str());
 
-        HANDLE hPort = CreateFile(m_usb_devices[i].c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
+        HANDLE hPort = CreateFile(m_usb_devices[i].c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 
         if(hPort == INVALID_HANDLE_VALUE)
         {
@@ -76,7 +76,7 @@ void CPosPrinter::InitUsb(int usbType)
 
 void CPosPrinter::InitOneUsb(wstring usb_path)
 {
-    HANDLE hPort = CreateFile(usb_path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
+    HANDLE hPort = CreateFile(usb_path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 
     if(hPort == INVALID_HANDLE_VALUE)
     {
@@ -235,8 +235,8 @@ void CPosPrinter::InitShouyin()
     //开始添加并口的端口
     InitBingkou();
 
-    //开始添加串口
-    InitCom();
+    //智能识别模式不再自动处理串口,串口的需要人工去选择类型
+    //InitCom();
 }
 
 /*
@@ -478,10 +478,12 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
         }
 
         POS_FeedLine();
+
         //订单来源
         string from_type = "订单来源:" + CLewaimaiString::UTF8ToANSI(order.m_from_type);
         POS_TextOut(from_type);
         POS_FeedLine();
+
         //订单号
         bool setting_printer_dingdanhao_big = false;
 
@@ -493,6 +495,7 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
         string order_num = "订 单 号:" + CLewaimaiString::UTF8ToANSI(order.m_order_num);
         POS_TextOut(order_num, false, setting_printer_dingdanhao_big);
         POS_FeedLine();
+
         //下单时间
         bool setting_printer_xiadanshijian_big = false;
 
@@ -504,6 +507,7 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
         string order_date = "下单时间:" + CLewaimaiString::UTF8ToANSI(order.m_order_date);
         POS_TextOut(order_date, false, setting_printer_xiadanshijian_big);
         POS_FeedLine();
+
         //配送时间
         bool setting_printer_peisongshijian_big = false;
 
@@ -551,6 +555,7 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
         string phone = "电话:" + CLewaimaiString::UTF8ToANSI(order.m_phone);
         POS_TextOut(phone, false, setting_printer_phone_big);
         POS_FeedLine();
+
         //地址
         bool setting_printer_address_big = false;
 
@@ -682,6 +687,7 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
         //结束商品详情打印
         POS_TextOut(lines);
         POS_FeedLine();
+
         //开始打印其他的费用
         bool is_other_money = false;
         bool setting_printer_price_big = false;
@@ -775,6 +781,7 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
         //最后显示总价
         POS_TextOut("总计:¥" + CLewaimaiString::DoubleToString(order.m_price, 2), false, setting_printer_price_big, 2);
         POS_FeedLine();
+
         //显示付款方式
         bool setting_printer_pay_big = false;
 
@@ -791,11 +798,28 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
         std::string order_no = order.m_order_no;
         order_no = CLewaimaiString::UTF8ToANSI(order_no);
 
-        POS_Reset();
-        POS_OutQRCode(order_no);
+        CBitmapHelper helper;
+        helper.LoadImage(L"D:\\800.bmp");
 
-        Gdiplus::Bitmap bmp(L"D:\\aaa.jpg");
-        PrintBmp(&bmp);
+		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);;
+		}
+
+		//二值化
+		helper.Image2Values();
+
+        PrintBmp(helper.getBmp());
 
         //走纸几行再切
         POS_FeedLine();
@@ -1230,7 +1254,7 @@ int CPosPrinter::WriteBuf(const unsigned char* buf, int len)
         {
             HANDLE hPort = (*it).hPort;
 
-            if((*it).type == 3)
+            if((*it).type == 1 || (*it).type == 3)
             {
                 //串口,同步写数据
                 //LOG_INFO("before com writefile handle:" << hPort);
@@ -1952,256 +1976,61 @@ std::vector<std::string> CPosPrinter::HandleBiaoqianFoodname(std::string oldname
     return newnameArray;
 }
 
-void ToGray(Bitmap * pOrgBitmap, Bitmap **pDesBitmap)
-{
-
-    int width = pOrgBitmap->GetWidth();
-    int height = pOrgBitmap->GetHeight();
-
-    switch(pOrgBitmap->GetPixelFormat())   //像素格式不同,灰度化处理方式也不同
-    {
-    case PixelFormat24bppRGB:
-    {
-        Rect rect(0, 0, width, height);
-        BYTE byte;
-        BitmapData bitmapData_org, bitmapData_new;
-        Bitmap *pGrayImg = new Bitmap(width, height, PixelFormat8bppIndexed);  // 建立带索引的位图PixelFormat8bppIndexed,此种格式的位图,一个像素占一个字节
-        ColorPalette *pal = (ColorPalette *)malloc(sizeof(ColorPalette) + 256 * sizeof(ARGB));
-        pal->Count = 256;
-        pal->Flags = 2;
-
-        for(int m = 0; m < 256; m++)
-        {
-            pal->Entries[m] = Color::MakeARGB(255, m, m, m);
-        }
-
-        pGrayImg->SetPalette(pal);
-        free(pal); // 释放掉malloc开辟的空间
-        pGrayImg->LockBits(&rect, ImageLockModeWrite, PixelFormat8bppIndexed, &bitmapData_new); //锁定位图,然后对其进行读写内存操作,相关信息保存到BitmapData中
-        Status iSucess = pOrgBitmap->LockBits(
-                             &rect,
-                             ImageLockModeWrite,
-                             PixelFormat24bppRGB,
-                             &bitmapData_org);
-
-        BYTE *p = (BYTE*)bitmapData_org.Scan0; //原图rect区域内存位置的起始指针,以BYTE作为单元类型
-        BYTE *q = (BYTE*)bitmapData_new.Scan0;  //目标位图rect区域的起始指针
-        BYTE *pt = p, *qt = q;
-        BYTE val;
-
-        //  灰度化
-        for(int i = 0; i < height; i++)
-        {
-            pt = p + i * bitmapData_org.Stride;  //Stride为rect区域一行所占的字节数
-            qt = q + i * bitmapData_new.Stride;
-
-            for(int j = 0; j < width; j++)
-            {
-                val = *(pt) * 0.114 + (*(pt + 1)) * 0.587 + (*(pt + 2)) * 0.299;
-
-                if(val > 255)
-                {
-                    val = 255;
-                }
-
-                if(val < 0)
-                {
-                    val = 0;
-                }
-
-                *qt = val;  //根据红绿蓝求出此像素的灰度值,写入目标位图内存*qt中
-                pt += 3;    //原图一个像素占3个字节,所以,计算下一个像素灰度值时,指针要挪移3个单元
-                qt += 1;    //目标位图一个像素占一个字节,所以,设置下一个像素灰度值时,指针只需挪移1个单元
-
-            }
-        }
-
-        pOrgBitmap->UnlockBits(&bitmapData_org); //源图像撤销锁定
-        pGrayImg->UnlockBits(&bitmapData_new);   // 目标图像撤销锁定
-        *pDesBitmap = pGrayImg;                    //将目标图像的地址保存到*pDesBitmap中
-    }
-    break;
-
-    case PixelFormat32bppARGB:
-    {
-        Rect rect(0, 0, width, height);
-        BYTE byte;
-        BitmapData bitmapData_org, bitmapData_new;
-        Bitmap *pGrayImg = new Bitmap(width, height, PixelFormat8bppIndexed);
-        ColorPalette *pal = (ColorPalette *)malloc(sizeof(ColorPalette) + 256 * sizeof(ARGB));
-        pal->Count = 256;
-        pal->Flags = 0;
-
-        for(int m = 0; m < 256; m++)
-        {
-            pal->Entries[m] = Color::MakeARGB(255, m, m, m);
-        }
-
-        pGrayImg->SetPalette(pal);
-        free(pal); // 释放掉malloc开辟的空间
-
-        pGrayImg->LockBits(&rect, ImageLockModeWrite, PixelFormat8bppIndexed, &bitmapData_new);
-        Status iSucess = pOrgBitmap->LockBits(
-                             &rect,
-                             ImageLockModeWrite,
-                             PixelFormat32bppARGB,
-                             &bitmapData_org);
-
-        BYTE *p = (BYTE*)bitmapData_org.Scan0;
-        BYTE *q = (BYTE*)bitmapData_new.Scan0;
-        BYTE *pt = p, *qt = q;
-        BYTE val;
-
-        //  灰度化
-        for(int i = 0; i < height; i++)
-        {
-            pt = p + i * bitmapData_org.Stride;
-            qt = q + i * bitmapData_new.Stride;
-
-            for(int j = 0; j < width; j++)
-            {
-                val = *(pt + 1) * 0.114 + (*(pt + 2)) * 0.587 + (*(pt + 3)) * 0.299;
-
-                if(val > 255)
-                {
-                    val = 255;
-                }
-
-                if(val < 0)
-                {
-                    val = 0;
-                }
-
-                *qt = val;
-                pt += 4;
-                qt += 1;
-            }
-        }
-
-        pOrgBitmap->UnlockBits(&bitmapData_org);
-        pGrayImg->UnlockBits(&bitmapData_new);
-        *pDesBitmap = pGrayImg;
-    }
-    break;
-
-    case PixelFormat8bppIndexed:  //之所以同为PixelFormat8bppIndexed还转换,
-        // 是因为用m_pMemBmp=m_pImage->Clone(rect,m_pImage->GetPixelFormat())
-        //克隆的内存位图,读写速度不如直接new Bitmap()生成的位图的读写速度快,不知道是为什么?
-        // 所以这里,将Clone的位图再用new Bitmap 转换一下
-    {
-        Rect rect(0, 0, width, height);
-        BYTE byte;
-        BitmapData bitmapData_org, bitmapData_new;
-        Bitmap *pGrayImg = new Bitmap(width, height, PixelFormat8bppIndexed);
-        ColorPalette *pal = (ColorPalette *)malloc(sizeof(ColorPalette) + 256 * sizeof(ARGB));
-        pal->Count = 256;
-        pal->Flags = 0;
-
-        for(int m = 0; m < 256; m++)
-        {
-            pal->Entries[m] = Color::MakeARGB(255, m, m, m);
-        }
-
-        pGrayImg->SetPalette(pal);
-        free(pal); // 释放掉malloc开辟的空间
-
-        pGrayImg->LockBits(&rect, ImageLockModeWrite, PixelFormat8bppIndexed, &bitmapData_new);
-        Status iSucess = pOrgBitmap->LockBits(
-                             &rect,
-                             ImageLockModeWrite,
-                             PixelFormat8bppIndexed,
-                             &bitmapData_org);
-
-        BYTE *p = (BYTE*)bitmapData_org.Scan0;
-        BYTE *q = (BYTE*)bitmapData_new.Scan0;
-        BYTE *pt = p, *qt = q;
-        BYTE val;
-
-        //  灰度化
-        for(int i = 0; i < height; i++)
-        {
-            pt = p + i * bitmapData_org.Stride;
-            qt = q + i * bitmapData_new.Stride;
-
-            for(int j = 0; j < width; j++)
-            {
-                val = *pt;
-                *qt = val;
-                pt += 1;
-                qt += 1;
-            }
-        }
-
-        pOrgBitmap->UnlockBits(&bitmapData_org);
-        pGrayImg->UnlockBits(&bitmapData_new);
-        *pDesBitmap = pGrayImg;
-    }
-    break;
-
-    default:
-        *pDesBitmap = pOrgBitmap;
-        break;
-    }
-
-}
-
 void CPosPrinter::PrintBmp(Bitmap* bmp)
 {
-	//设置行间距
+    //设置行间距为0
     unsigned char data[3] = { 0x1B, 0x33, 0x00 };
     WriteBuf(data, 3);
 
-    memset(data, 0, 3);
-
-    Gdiplus::Color pixelColor;
+	//设置图像居中对齐
+	unsigned char data2[3] = { 0x1B, 0x61, 0x01 };
+	WriteBuf(data2, 3);
 
+	//选择位图模式
     unsigned char escBmp[5] = { 0x1B, 0x2A, 0x21, 0x00, 0x00 };
 
-    unsigned int nWidth = bmp->GetWidth();
-    unsigned int nHeight = bmp->GetHeight();
+	unsigned int nWidth = bmp->GetWidth();
+	unsigned int nHeight = bmp->GetHeight();
 
     escBmp[3] = (unsigned char)(nWidth % 256);
-    escBmp[4] = (unsigned char)(nHeight / 256);
+    escBmp[4] = (unsigned char)(nWidth / 256);
+
+	Gdiplus::Color pixelColor;
 
     //循环图片像素打印图片
-    //循环高
-    for(int i = 0; i < (nHeight / 24 + 1); i++)
+    for(unsigned int i = 0; i < (nHeight / 24 + 1); i++)
     {
         //设置模式为位图模式
         WriteBuf(escBmp, 5);
 
+        unsigned char* dataTmp = new unsigned char[nWidth * 3];
+        memset(dataTmp, 0, nWidth * 3);
+
         //循环宽
-        for(int j = 0; j < nWidth; j++)
+        for(unsigned int j = 0; j < nWidth; j++)
         {
-            for(int k = 0; k < 24; k++)
+            for(unsigned int k = 0; k < 24; k++)
             {
-                if(((i * 24) + k) < nHeight)  // if within the BMP size
+                //找到有像素的区域,也就是未超出位图高度的区域
+                if(((i * 24) + k) < nHeight)
                 {
                     bmp->GetPixel(j, (i * 24) + k, &pixelColor);
                     unsigned char r = pixelColor.GetR();
 
                     if(r == 0)
                     {
-                        data[k / 8] += (unsigned char)(128 >> (k % 8));
+                        //如果本来是黑色的像素,那么就把对应的数据位设置为1
+                        dataTmp[j * 3 + k / 8] += (unsigned char)(128 >> (k % 8));
                     }
                 }
             }
-
-			data[0] = 0xFF;
-			data[1] = 0xFF;
-			data[2] = 0xFF;
-
-            //一次写入一个data,24个像素
-            WriteBuf(data, 3);
-
-            memset(data, 0, 3);
         }
 
-        //换行,打印第二行
-        unsigned char data2[1] = { 0x0A };
-        WriteBuf(data2, 1);
-    } // data
+        WriteBuf(dataTmp, nWidth * 3);
+        delete[] dataTmp;
+    }
 
-    unsigned char data3[2] = { 0x0A, 0x0A };
-    WriteBuf(data3, 2);
+	//还原默认的行间距
+	unsigned char data3[2] = { 0x1B, 0x32};
+	WriteBuf(data3, 2);
 }

+ 1 - 4
lewaimai_pos_windows/tool/CPosPrinter.h

@@ -3,9 +3,6 @@
 #include "../pch/pch.h"
 #include "../order/CWaimaiOrder.h"
 
-#include <gdiplus.h>
-using namespace Gdiplus;
-
 //SetupDiGetInterfaceDeviceDetail所需要的输出长度,定义足够大
 #define INTERFACE_DETAIL_SIZE 1024
 
@@ -101,7 +98,7 @@ private:
 	boost::asio::io_service m_io;
 	boost::asio::ip::tcp::socket m_socket;
 
-	//这个是当前的输出模式,是收银模式还是厨房打印模式
+	//这个是当前的输出模式,是CreateFile模式,还是socket模式
 	int m_type;
 
 	//usb打印机的描述

+ 2 - 0
lewaimai_pos_windows_server/obj/x86/Release/lewaimai.e085afd9.tlog/lewaimai_pos_windows_server_linux.lastbuildstate

@@ -0,0 +1,2 @@
+#TargetFrameworkVersion=:PlatformToolSet=Remote_GCC_1_0:EnableManagedIncrementalBuild=:VCToolArchitecture=:WindowsTargetPlatformVersion=
+Release|x86|E:\work\code\lewaimai_pos_windows\|

+ 4 - 2
lewaimai_pos_windows_server/obj/x86/Release/lewaimai_pos_windows_server_linux.log

@@ -1,2 +1,4 @@
-  Cleaning remote project directory
-D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Application Type\Linux\1.0\Linux.targets(210,6): error : Could not connect to the remote system. Please verify your connection settings, and that your machine is on the network and reachable.
+D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppBuild.targets(391,5): warning MSB8028: 中间目录(E:\work\code\lewaimai_pos_windows\lewaimai_pos_windows_server\obj\x86\Release\)包含从另一个项目(zhipuzi_pos_windows_server_linux.vcxproj)共享的文件。   这会导致错误的清除和重新生成行为。
+  Validating sources
+  Copying sources remotely to '172.16.1.71'
+D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Application Type\Linux\1.0\Linux.targets(162,5): error : Could not connect to the remote system. Please verify your connection settings, and that your machine is on the network and reachable.