Spelt / ZXing.Delphi

ZXing Barcode Scanning object Pascal Library for Delphi VCL and Delphi Firemonkey
Apache License 2.0
471 stars 206 forks source link

ZXing QR Code Image Result output omits all ZEROS (0) #121

Closed Deyken closed 2 years ago

Deyken commented 3 years ago

Whenever I provide the QRCode object (TDelphiZXingQRCode) with a string containing the character ZERO (0), situated anywhere in the middle and/or at the end of a string, those zeros are simply omitted from the result string. The QR Code generated just does not have any zeros in it, which delivers an incorrect scan result.

Is there a setting I should set to change this? My code is below for ease of reference:

` procedure TfrmCustomer.RegisterNewVisit; var QRCode: TDelphiZXingQRCode; QRCodeData : String; Row, Column: Integer; vBitMapData : TBitmapData; ImageMapped : Boolean; begin ImageMapped := FALSE;

//AUTOMATICALLY USE THE CURRENT LOGGED IN USER ACCOUNT NUMBER: if Assigned(FCustomer) then begin //edtQRData2.Text := frmMain.AccountNo; //for test purposes - I fill this out manually ATM QRCodeData := edtQRData2.Text; //RDQ(FCustomer.GetValue('customerId').ToString); if QRCodeData = '' then begin ShowMessage('Your Customer Account did not load correctly. Please log in again?'); Exit; end; end;

//Will produce another QR Code for the Waiter to scan: QRCode := TDelphiZXingQRCode.Create; try QRCode.Data := QRCodeData; //TQRCodeEncoding = (qrAuto, qrNumeric, qrAlphanumeric, qrISO88591, qrUTF8NoBOM, qrUTF8BOM); QRCode.Encoding := TQRCodeEncoding(qrAlphanumeric); QRCode.QuietZone := 4; //default value? QRImageVisit.SetSize(QRCode.Rows, QRCode.Columns);

//THIS DRAWS THE ACTUAL IMAGE FROM THE DATA ARRAY IN QRCode, decided by the data
if QRImageVisit.Canvas.Bitmap.Map (TMapAccess.maWrite, vBitMapData) then
  begin
    try
      for Row := 0 to QRCode.Rows - 1 do
        begin
          for Column := 0 to QRCode.Columns - 1 do
          begin
            if (QRCode.IsBlack[Row, Column]) then
            begin
              //DRAW FMX PIXEL BLACK                  
              vBitmapData.SetPixel (Row, Column, TAlphaColors.Black); // set the pixel color at x, y
            end else
            begin
              //DRAW FMX PIXEL WHITE                  
              vBitmapData.SetPixel (Row, Column, TAlphaColors.White); // set the pixel color at x, y
            end;
          end;
        end;

    finally
      ImageMapped := TRUE;
      QRImageVisit.Canvas.Bitmap.Unmap(vBitMapData);
      imgQRCode2.Bitmap.Assign(QRImageVisit);
    end;
  end;

finally QRCode.Free; end;

//DISPLAY THIS IMAGE if ImageMapped then ShowMessage('Show this QR Code to your Waiter to register your new visit. This will earn you additional Loyalty Points!'); end;

`

geoffsmith82 commented 3 years ago

I think this is the wrong project for this issue. Have a look at https://github.com/foxitsoftware/DelphiZXingQRCode/pull/4

Spelt commented 3 years ago

Hi

I think you are at the wrong project.

This one does not generate QR codes but reads them.

Good luck!

Op 13 jul. 2021 om 10:59 heeft Deyken @.***> het volgende geschreven:

 Whenever I provide the QRCode object (TDelphiZXingQRCode) with a string containing the character ZERO (0), situated anywhere in the middle and/or at the end of a string, those zeros are simply omitted from the result string. The QR Code generated just does not have any zeros in it, which delivers an incorrect scan result.

Is there a setting I should set to change this? My code is below for ease of reference:

`procedure TfrmCustomer.RegisterNewVisit; var QRCode: TDelphiZXingQRCode; QRCodeData : String; Row, Column: Integer; vBitMapData : TBitmapData; ImageMapped : Boolean; begin ImageMapped := FALSE;

//AUTOMATICALLY USE THE CURRENT LOGGED IN USER ACCOUNT NUMBER: if Assigned(FCustomer) then begin //edtQRData2.Text := frmMain.AccountNo; //for test purposes - I fill this out manually ATM QRCodeData := edtQRData2.Text; //RDQ(FCustomer.GetValue('customerId').ToString); if QRCodeData = '' then begin ShowMessage('Your Customer Account did not load correctly. Please log in again?'); Exit; end; end;

//Will produce another QR Code for the Waiter to scan: QRCode := TDelphiZXingQRCode.Create; try QRCode.Data := QRCodeData; //TQRCodeEncoding = (qrAuto, qrNumeric, qrAlphanumeric, qrISO88591, qrUTF8NoBOM, qrUTF8BOM); QRCode.Encoding := TQRCodeEncoding(qrAlphanumeric); QRCode.QuietZone := 4; //default value? QRImageVisit.SetSize(QRCode.Rows, QRCode.Columns);

//THIS DRAWS THE ACTUAL IMAGE FROM THE DATA ARRAY IN QRCode, decided by the data if QRImageVisit.Canvas.Bitmap.Map (TMapAccess.maWrite, vBitMapData) then begin try for Row := 0 to QRCode.Rows - 1 do begin for Column := 0 to QRCode.Columns - 1 do begin if (QRCode.IsBlack[Row, Column]) then begin //DRAW FMX PIXEL BLACK
vBitmapData.SetPixel (Row, Column, TAlphaColors.Black); // set the pixel color at x, y end else begin //DRAW FMX PIXEL WHITE
vBitmapData.SetPixel (Row, Column, TAlphaColors.White); // set the pixel color at x, y end; end; end;

finally
  ImageMapped := TRUE;
  QRImageVisit.Canvas.Bitmap.Unmap(vBitMapData);
  imgQRCode2.Bitmap.Assign(QRImageVisit);
end;

end; finally QRCode.Free; end;

//DISPLAY THIS IMAGE if ImageMapped then ShowMessage('Show this QR Code to your Waiter to register your new visit. This will earn you additional Loyalty Points!'); end;`

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.