2010-04-07 110 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