最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - While improving the escpos image printing speed, the image output is strange - Stack Overflow

programmeradmin2浏览0评论

I improved a lot on my old sources by checking many questions.

I changed it to C++ source by referring to the link.

I confirmed that it takes a long time to print the image when using 24 dots.

I found out that the solution to this problem is to change it to 8dot.

8dot image If you set it to 24dot, it will be printed normally. 24dot image

I'd like to know if I'm missing anything.

CString GetLogo(LPCTSTR fileName) 
{
    CString csFileName = fileName;
    csFileName = csFileName.MakeUpper();


    BitmapData data = GetBitmapData(csFileName.GetBuffer());
    std::vector<bool>& dots = data.Dots;

    unsigned char widthLow = static_cast<unsigned char>(data.Width & 0xFF);
    unsigned char widthHigh = static_cast<unsigned char>((data.Width >> 8) & 0xFF);

    int offset = 0;

    CString result;

    
    result.AppendChar((char)0x1B);
    result.AppendChar('@');                     
    result.AppendChar((char)0x1B);
    result.AppendChar('3');
    result.AppendChar((char)8);      

    while (offset < data.Height)
    {
        result.AppendChar((char)0x1B);
        result.AppendChar('*');   
        result.AppendChar((char)1);
        result.AppendChar((char)widthLow); 
        result.AppendChar((char)widthHigh);

        for (int x = 0; x < data.Width; ++x)
        {
            unsigned char slice = 0;
            for (int b = 0; b < 8; ++b)
            {
                int y = offset + b;
                int i = (y * data.Width) + x;
                bool v = (i < (int)dots.size()) ? dots[i] : false;
                slice |= (unsigned char)((v ? 1 : 0) << (7 - b));
            }
            result.AppendChar((char)slice);
        }
        offset += 8;
        result.AppendChar((char)0x0A);
    }
    result.AppendChar((char)0x1B);
    result.AppendChar('3');
    result.AppendChar((char)30);


    return result;
}
发布评论

评论列表(0)

  1. 暂无评论