开发者

Large black line appears when printing bmp files using the EPL2 print language

This is the 3rd part to this topic. Part 1, Part 2..

I was successfully able to print my monochrome bitmap to my printer, however there is a large black stripe along the right of the image when the item prints.

Here is the original

Large black line appears when printing bmp files using the EPL2 print language

(Scanned in)What the printer printed

Large black line appears when printing bmp files using the EPL2 print language

Code to generate binary blob

Rectangle rect = new Rectangle(0, 0, Bitmap.Width, Bitmap.Height);
System.Drawing.Imaging.BitmapData bmpData = null;
byte[] bitVaues = null;
int stride = 0;
try
{
    bmpData = Bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, Bitmap.PixelFormat);
    IntPtr ptr = bmpData.Scan0;
    stride = bmpData.Stride;
    int bytes = bmpData.Stride * Bitmap.Height;
    bitVaues = new byte[bytes];
    System.Runtime.InteropServices.Marshal.Copy(ptr, bitVaues, 0, bytes);
}
finally
{
    if (bmpData != null)
        Bitmap.UnlockBits(bmpData);
}

string str = String.Format("GW{0},{1},{2},{3},", X, Y, stride, Bitmap.Height);
byte[] ascii = Encoding.ASCII.GetBytes(str);
byte[] buffer = new byte[ascii.Length + bitVaues.Length + 1];
Buffer.BlockCopy(ascii, 0, buffer, 0, ascii.Length);
Buffer.BlockCopy(bitVaues, 0, buffer, ascii.Length, bitVaues.Length);
buffer[buffer.Length - 1] = (byte)'\n';
return buffer;

My initial theory is the BMP format is开发者_运维技巧 adding that line as a end of line marker and is not viable when rendered. I am thinking I may have to reparse the file after I have the binary array and take out the 00 00 00 at the end of every line. But I am posting here in case anyone thinks of a better way.


Microsoft bitmaps are always padded to an even 32 bits. When you generate the bitmap, round the width up to a multiple of 32 and you should be fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜