2015-10-09 373 views
-2

好的。過了一段時間我有一個工作的maded程序。下面是Delphi代碼:在POS打印機上打印圖像

procedure TNativePrint.DoPrintBitmap(const ABitmap : TBitmap; const BitsPerSlice : byte); 
const 
    Threshhold = 127; 
type 
    TBitArray = array of boolean; 
    TRGBTripleArray = ARRAY[Word] of TRGBTriple; 
    pRGBTripleArray = ^TRGBTripleArray; // Use a PByteArray for pf8bit color. 
var 
    vCol : integer; 
    vRow : integer; 
    vIndex : integer; 
    vSliceIndex : integer; 
    vBytePos : integer; 
    vBitPos : integer; 
    vOffset : integer; 
    vLuminance : integer; 
    vLine: pRGBTripleArray; 
    vPixel: TRGBTriple; 
    vDots: TBitArray; 
    vSlice : byte; 
    vBit : byte; 
    vTmpBit: byte; 
    vVal: boolean; 
    vTempStr : string; 
begin 
    if not Assigned(ABitmap) then exit; 

    try 
    ABitmap.PixelFormat := pf24bit; 
    SetLength(vDots, (ABitmap.Height * ABitmap.Width)); 
    vIndex := 0; 

    for vRow := 0 to ABitmap.Height-1 do begin 
     vLine := ABitmap.Scanline[vRow]; 
     for vCol := 0 to ABitmap.Width-1 do begin 
     vPixel := vLine[vCol]; 
     vLuminance := Trunc((vPixel.rgbtRed * 0.3) + (vPixel.rgbtGreen * 0.59) + (vPixel.rgbtBlue * 0.11)); 
     vDots[vIndex] := (vLuminance < Threshhold); 
     inc(vIndex); 
     end; 
    end; 

    DoSetLineSpacing(24); 
    DoAddLine(' '); 

    vOffset := 0; 
    while (vOffset < ABitmap.Height) do begin 
     DoAddLine(#$1B'*'#33+AnsiChar(Lo(ABitmap.Width))+AnsiChar(Hi(ABitmap.Width)), false); 

     vTempStr := ''; 
     for vCol := 0 to ABitmap.Width-1 do begin 
     for vSliceIndex := 0 to 2 do begin 
      vSlice := 0; 
      for vBit := 0 to 7 do begin 
      vBytePos := (((vOffset div 8) + vSliceIndex) * 8) + vBit; 
      vBitPos := (vBytePos * ABitmap.Width) + vCol; 

      vVal := false; 
      if (vBitPos < Length(vDots)) then begin 
       vVal := vDots[vBitPos]; 
      end; 

      vTmpBit := iff(vVal, 1, 0); 
      vSlice := vSlice or (vTmpBit shl (7 - vBit)); 
      end; 

      vTempStr := vTempStr + AnsiChar(vSlice); 
     end; 
     end; 

     inc(vOffset, 24); 
     DoAddLine(vTempStr); 
    end; 

    DoSetLineSpacing(0); 
    DoAddLine(' '); 
    finally 
    vDots := nil; 
    end; 
end; 

圖片打印出來,但是你可以在我的Picture看到,在每行之後,我有自由的空間。正如你可以在源代碼中看到的,在打印圖像之前,我將linespacing設置爲24,但這沒有幫助。有人可以解釋如何解決它?

+0

我有編輯我的帖子,現在你可以選擇源 –

+0

剛剛更新的第一篇文章,主要部分工作,有人可以幫助修復一個小東西) –

回答

0

的解決方案是在頁模式下打印輸出圖像:使用ESC'L」命令 設置打印區域ESC‘W’xL的XH基yH的DXL DXH DYL DYH 打印輸出圖像使用我的代碼的第一篇文章

啓用頁模式

此外,此問題僅出現在EPSON TM-T88V上,您可以在其他打印機上以標準模式打印。

0

我只是用你的代碼進行了一些修改,以便在Epson ESC打印機上打印位圖,並且工作正常。

1.去除所有自由空間:

DoSetLineSpacing(24); 
DoSetLineSpacing(0); 
DoAddLine(' '); 
DoAddLine(' '); 

2.1936

DoAddLine(vTempStr) 

添加CRLF(#13#10)vTempStr字符串:

DoAddLine(vTempStr+#13#10); 

完蛋了..