2010-04-07 107 views
1

这是本主题的第3部分。 Part 1Part 2.使用EPL2打印语言打印bmp文件时出现大的黑线

我成功地将我的单色位图打印到我的打印机,但是当打印项目时,图像右侧有一个大的黑色条纹。

原来这里是

enter image description here

(扫描中)打印机打印什么

enter image description here

代码,以生成二进制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; 

我最初的理论是日e BMP格式将该行添加为行结束标记,并且在呈现时不可行。我想我可能不得不在我有二进制数组后,重新分析文件,并在每行结束时取出00 00 00。但我在这里发帖,以防有人想到更好的办法。

回答

5

微软位图总是被填充到偶数32位。当你生成位图时,将宽度舍入为32的倍数,你应该没问题。

+1

啊,我只能四舍五入到下一个8位。 – 2010-04-07 19:52:35

+0

我把它四舍五入,黑色的酒吧消失了。 – 2010-04-07 19:56:44