J'ai imprimé une image bitmap de l'imprimante epson TM-T82 en utilisant le code delphi7. J'envoie des commandes ESCPOS à l'imprimante epson pour imprimer une image bitmap. Cette image bitmap imprimée contient des lignes blanches dans le logo. Lorsque j'utilise l'utilitaire d'impression Epson avec le même logo, il imprime très bien.L'image sur le reçu de l'imprimante thermique epson affiche des lignes horizontales blanches
Est-ce que quelqu'un sait comment résoudre ce problème?
Voici mon code:
unit ssESCPosPrintBitmap;
interface
type
// *** -------------------------------------------------------------------------
// *** INTERFACE: IssESCPosPrintBitmap
// *** -------------------------------------------------------------------------
IssESCPosPrintBitmap = interface(IInterface)
['{3F279585-6D2E-451F-AF97-76F0E07A70DF}']
function RenderBitmap(const ABitmapFilename: string): string;
end;
function _ESCPosPrintBitmap(): IssESCPosPrintBitmap;
implementation
uses
Windows,
Graphics,
Math;
type
TRGBTripleArray = ARRAY[Word] of TRGBTriple;
pRGBTripleArray = ^TRGBTripleArray; // Use a PByteArray for pf8bit color.
// *** -------------------------------------------------------------------------
// *** RECORD: TBitmapData
// *** -------------------------------------------------------------------------
TBitmapData = record
Dots : array of Boolean;
Height : Integer;
Width : Integer;
end;
// *** -------------------------------------------------------------------------
// *** CLASS: TssESCPosPrintBitmap
// *** -------------------------------------------------------------------------
TssESCPosPrintBitmap = class(TInterfacedObject, IssESCPosPrintBitmap)
private
FLumThreshold : Integer;
FBitmap : TBitmap;
FBitmapData : TBitmapData;
procedure LoadBitmapData();
public
constructor Create();
destructor Destroy; override;
function RenderBitmap(const ABitmapFilename: string): string;
end;
const
C_DEFAULT_THRESHOLD = 127;
function _ESCPosPrintBitmap(): IssESCPosPrintBitmap;
begin
Result := TssESCPosPrintBitmap.Create();
end;
{ TssESCPosPrintBitmap }
{-------------------------------------------------------------------------------
Procedure: TssESCPosPrintBitmap.Create
Author: bvonfintel
DateTime: 2015.01.06
Arguments: None
Result: None
-------------------------------------------------------------------------------}
constructor TssESCPosPrintBitmap.Create;
begin
inherited;
FBitmap := TBitmap.Create();
FLumThreshold := C_DEFAULT_THRESHOLD;
end;
procedure TssESCPosPrintBitmap.LoadBitmapData;
var
LIndex : Integer;
LX : Integer;
LY : Integer;
LLine : pRGBTripleArray;
LPixel : TRGBTriple;
LLum : Integer;
begin
LIndex := 0;
FBitmapData.Height := FBitmap.Height;
FBitmapData.Width := FBitmap.Width;
SetLength(FBitmapData.Dots, FBitmap.Width * FBitmap.Height);
for LY := 0 to FBitmap.Height-1 do begin
LLine := FBitmap.ScanLine[LY];
for LX := 0 to FBitmap.Width-1 do begin
LPixel := LLine[LX];
LLum := Trunc((LPixel.rgbtRed * 0.3) + (LPixel.rgbtGreen * 0.59) + (LPixel.rgbtBlue * 0.11));
FBitmapData.Dots[LIndex] := (LLum < FLumThreshold);
Inc(LIndex);
end;
end;
end;
function TssESCPosPrintBitmap.RenderBitmap(const ABitmapFilename: string): string;
var
LOffset : Integer;
LX : Integer;
LSlice : Byte;
LB : Integer;
LK : Integer;
LY : Integer;
LI : Integer;
LV : Boolean;
LVI : Integer;
begin
// *** load the Bitmap from the file
FBitmap.LoadFromFile(ABitmapFilename);
FBitmap.PixelFormat := pf24bit;
// *** Convert the bitmap to an array of B/W pixels
LoadBitmapData();
// *** Set the line spacing to 24 dots, the height of each "stripe" of the
// *** image that we're drawing
Result := #27'3'#24;
LOffset := 0;
while (LOffset < FBitmapData.Height) do begin
Result := Result + #27;
Result := Result + '*'; // Bit image mode
Result := Result + #33; // 24-dot double density
Result := Result + Char(Lo(FBitmapData.Width));
Result := Result + Char(Hi(FBitmapData.Width));
for LX := 0 to FBitmapData.Width -1 do begin
for LK := 0 to 2 do begin
LSlice := 0;
for LB := 0 to 7 do begin
LY := (((LOffset div 8) + LK) * 8) + LB;
LI := (LY * FBitmapData.Width) + LX;
LV := False;
if (LI < Length(FBitmapData.Dots)) then
LV := FBitmapData.Dots[LI];
LVI := IfThen(LV, 1, 0);
LSlice := LSlice or (LVI shl (7 - LB));
end;
Result := Result + Chr(LSlice);
end;
end;
LOffset := LOffset + 24;
Result := Result + sLineBreak;
end;
// *** Restore the line spacing to the default of 30 dots
Result := Result + #27'3'#30 + sLineBreak + sLineBreak + sLineBreak;
end;
Function TfrmEpsonPrint.PrintLabel(EPLCode : String): Boolean;
var
ADevice, ADeviceName, ADevicePort: array[0..255]of Char;
PrinterHandle: THandle;
DocInfo: TDocInfo1;
dwJob: cardinal;
dwBytesWritten: cardinal;
AUtf8: UTF8string;
ADeviceMode: THandle;
Index: Integer;
begin
Try
Try
Result := True;
//printer
Printer.Refresh;
Index := Printer.Printers.IndexOf('EPSON TM-T82 Receipt');
If Index >= 0 Then
Printer.PrinterIndex := Index
Else
Begin
ShowMessage('EPSON TM-T82 Receipt Printer not found. Please add Generic/Text Only Printer with name 2824');
Result := False;
Exit;
End;
Printer.GetPrinter(ADevice, ADeviceName, ADevicePort, ADeviceMode);
//Need a handle to the printer
if not OpenPrinter(ADevice, PrinterHandle, nil) Then
Exit;
//Fill in the structure with info about this "document"
DocInfo.pDocName := PChar('Label.txt');
DocInfo.pOutputFile := nil;
DocInfo.pDatatype := 'RAW';
//Inform the spooler the document is beginning
dwJob := StartDocPrinter(PrinterHandle, 1, @DocInfo);
if dwJob = 0 then
begin
ClosePrinter(PrinterHandle);
PrinterHandle := 0;
Exit;
end;
//Start a page
if not StartPagePrinter(PrinterHandle) then
begin
EndDocPrinter(PrinterHandle);
ClosePrinter(PrinterHandle);
PrinterHandle := 0;
Exit;
end;
EPLCode := _ESCPosPrintBitmap.RenderBitmap('C:\POS\RecTopImage1.bmp');
// EPLCode := EPLCode + #29'V'#1;
//epl code...
AUtf8 := UTF8string(EPLCode);
WritePrinter(PrinterHandle, @AUtf8[1], Length(AUtf8), dwBytesWritten);
//End the page
if not EndPagePrinter(PrinterHandle) then
begin
EndDocPrinter(PrinterHandle);
ClosePrinter(PrinterHandle);
PrinterHandle := 0;
Exit;
end;
//Inform the spooler that the document is ending
if not EndDocPrinter(PrinterHandle) then
begin
ClosePrinter(PrinterHandle);
PrinterHandle := 0;
Exit;
end;
//Tidy up the printer handle
ClosePrinter(PrinterHandle);
PrinterHandle := 0;
Except
End;
Finally
PrinterHandle := 0;
End;
End;
Cela n'a pas aidé, le même problème existe – embarcadero
Y a-t-il eu un changement? –
Pourriez-vous nous montrer une photo du résultat? –