【问题标题】:Print image on POS printer在 POS 打印机上打印图像
【发布时间】:2015-10-09 14:47:04
【问题描述】:

好的,伙计们。一段时间后,我制定了可行的程序。这是delphi代码:

    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 上看到的那样,在每一行之后我都有可用空间。正如您在源代码中看到的,在打印图像之前,我将行间距设置为 24,但这无济于事。有人能解释一下如何解决吗?

【问题讨论】:

  • 我已经编辑了我的帖子,现在你可以查看源代码
  • 刚刚更新了第一篇文章,主要部分已经工作,有人可以帮忙解决一个小问题)

标签: delphi delphi-xe escpos


【解决方案1】:

解决方法是在页面模式下打印输出图像: 使用 ESC'L' 命令启用页面模式 设置打印区域 ESC 'W' xL xH yL yH dxL dxH dyL dyH 使用我的第一篇文章中的代码打印输出图像

此问题仅在 EPSON TM-T88V 上存在,在其他打印机上您可以在标准模式下打印。

【讨论】:

    【解决方案2】:

    我刚刚使用您的代码稍加修改,在 Epson ESC 打印机上打印位图并且工作正常。

    1.删除所有空闲空间:

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

    2.开启

    DoAddLine(vTempStr) 
    

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

    DoAddLine(vTempStr+#13#10);
    

    就是这样..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      • 2014-11-16
      • 2012-10-11
      • 2017-10-21
      相关资源
      最近更新 更多