好了朋友们。一段时间后,我制定了可行的程序。这是德尔福代码:
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;
打印的图像,但正如您在我的图片上看到的那样,在每一行之后我都有可用空间。正如您在源代码中看到的,在打印图像之前,我将行距设置为 24,但这无济于事。有人可以解释如何解决它吗?