Изображение Epson Bitmap ESC Code Center

Вот что я настроил до сих пор

http://nicholas.piasecki.name/blog/2009/12/отправка-бит-изображения-в-an-epson-tm-t88iii-квитанция-принтер-использование-c-and-escpos/

Я следовал этому руководству, и теперь я могу распечатать растровое изображение на чековом принтере.

Но теперь я хотел бы центрировать изображение на принтере чеков и, похоже, понял, как реализовать это в его коде. Может кто-нибудь, пожалуйста, помогите мне понять, куда вставить пробелы для достижения этой цели?

Вот часть записи битового массива, взятая из кода:

    bw.Write(AsciiControlChars.Newline);
    bw.Write("                 Hello World!");
    bw.Write(AsciiControlChars.Newline);
    bw.Write("          "); 

^^^This bw.Write(" "); перемещает первую строку поверх

    // So we have our bitmap data sitting in a bit array called "dots."
    // This is one long array of 1s (black) and 0s (white) pixels arranged
    // as if we had scanned the bitmap from top to bottom, left to right.
    // The printer wants to see these arranged in bytes stacked three high.
    // So, essentially, we need to read 24 bits for x = 0, generate those
    // bytes, and send them to the printer, then keep increasing x. If our
    // image is more than 24 dots high, we have to send a second bit image
    // command.

    // Set the line spacing to 24 dots, the height of each "stripe" of the
    // image that we're drawing.
    bw.Write(AsciiControlChars.Escape);
    bw.Write('3');
    bw.Write((byte)24);

    // OK. So, starting from x = 0, read 24 bits down and send that data
    // to the printer.
    int offset = 0;

    while (offset < data.Height)
    {
        bw.Write(AsciiControlChars.Escape);
        bw.Write('*');         // bit-image mode
        bw.Write((byte)33);    // 24-dot double-density
        bw.Write(width[0]);  // width low byte
        bw.Write(width[1]);  // width high byte

        for (int x = 0; x < data.Width; ++x)
        {
            for (int k = 0; k < 3; ++k)
            {
                byte slice = 0;

                for (int b = 0; b < 8; ++b)
                {
                    int y = (((offset / 8) + k) * 8) + b;

                    // Calculate the location of the pixel we want in the bit array.
                    // It'll be at (y * width) + x.
                    int i = (y * data.Width) + x;

                    // If the image is shorter than 24 dots, pad with zero.
                    bool v = false;
                    if (i < dots.Length)
                    {
                        v = dots[i];
                    }

                    slice |= (byte)((v ? 1 : 0) << (7 - b));
                }

                bw.Write(slice);
            }
        }

        offset += 24;
        bw.Write(AsciiControlChars.Newline);
    }
    // Restore the line spacing to the default of 30 dots.
    bw.Write(AsciiControlChars.Escape);
    bw.Write('3');
    bw.Write((byte)30);
    bw.Write("Text Is awsome");
    bw.Write(AsciiControlChars.Newline);
}

person SuNnY_sYeD    schedule 03.02.2013    source источник


Ответы (1)


По сути, проблема заключается в том, что, поскольку мы вызвали режим растрового изображения, любой вставленный нами пробел на самом деле не добавлял пространства к потоку, поэтому, чтобы решить все это, вам нужно отключить режим растрового изображения в вашем вертикальном цикле и добавить пробелы, а затем просто переключите режим обратно в режим растрового изображения.

person SuNnY_sYeD    schedule 29.06.2013