我遇到了一个问题。我的位图图像有小线条分隔每个数据块,如前面的问题所示: How print bit Image TM-T88V
在此之后,我想出了另一个问题,现在整个图像被压扁了。增加行间距将图像分成12组3(如预期的那样),并且增大和减小偏移会拉长并压缩图像。
以下是图片:
我正在使用ESC / POS语言和C#。将位图存储在闪存中以及使用' GS'代码不是一种选择。
任何帮助都将不胜感激。
我在下面提供了我的代码:
private static byte[] ConvertMethodByteArray(tBitmapData bmpdata)
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
int offset = 0;
var iWidth = BitConverter.GetBytes(bmpdata.Width);
var iWidthPage = (bmpdata.Width * 2) + 30;
bw.Write((char)0x1B); //ASCII Escape
bw.Write((char)'L'); // PageMode
bw.Write((char)0x1B); //ASCII Escape
bw.Write((char)'W'); //Print region in pagemode
bw.Write((byte)0); //xl
bw.Write((byte)0); //xh
bw.Write((byte)0); //yl
bw.Write((byte)0); //yh
bw.Write((byte)0); //dxl
bw.Write((byte)0); //dxh
bw.Write((iWidthPage % 256)); //dyl
bw.Write((iWidthPage / 256)); //dyh
bw.Write((char)(0x1B)); // ASCII Escape
bw.Write((char)('T')); // Print Direction
bw.Write((byte)(0)); // Right to left
bw.Write((char)0x1B); // ASCII Escape character
bw.Write('3'); // Change line height
bw.Write((byte)24); // line height 24
while (offset < bmpdata.Height)
{
//bw.Write((char)0x1B); // ESC FF here prints each line then moves on
//bw.Write((char)0x0c); // FF prints and leaves printmode
//..(but leaves image in tact with lines)
bw.Write((char)0x1B); // ASCII Escape character
bw.Write('*'); // bit-image mode
bw.Write((byte)33); // 24 - dot double density
bw.Write(iWidth[0]); // Width low byte
bw.Write(iWidth[1]); // width hight byte
for (int x = 0; x < bmpdata.Width; x++)
{
// 24 dots = 24 bits = 3 bytes
for (int k = 0; k < 3; k++)
{
byte slice = 0;
// 8 bits in a byte
for (int b = 0; b < 8; b++)
{
// For calculating the y position we are currently trying to draw
int y = (((offset / 8) + k) * 8) + b;
// Calculate the position of y in the bit array
int i = (y * bmpdata.Width) + x;
// If the image (or stripe) is shorter than 24 pad with 0
bool v = false;
if (i < bmpdata.data.Length)
{
v = bmpdata.data[i];
}
// store the bit in the current byte, bitshift and
// ..or to get b in the correct location
slice |= (byte)((v ? 1 : 0) << (7 - b));
}
bw.Write(slice);
}
}
//Done with 1 24 dot pass, go to new line and increase offset
offset += 24;
bw.Write((char)0x0A);
}
bw.Write((char)0x0c); // FF exit pagemode and print data
bw.Write((char)0x1B); // ESC
bw.Write('3'); // Line spacing
bw.Write((byte)30); // 30
return ms.ToArray();
}
}