2017-05-24 525 views
1

我正在使用此Delphi-Unit。我不得不用這種舊Delphi實現,所以不要問有關: https://github.com/foxitsoftware/DelphiZXingQRCode由DelphiZXingQRCode編碼的QR碼無法通過ErrorCorrectionLevel解碼>低

它產生的QRcodes通過任何解碼器就好了解碼,只要我保持糾錯等級爲「低」。如果我增加糾錯級別,那麼生成的代碼就不能被我到目前爲止嘗試過的任何解碼器解碼。但是我被迫(通過標準)使用Medium的糾錯級別,不多不少。

但是不清楚如何提高糾錯水平(從現在起ecl)。我假設它在3491行的DelphiZXingQRCode文件中被硬編碼:Level.FBits:= 1.我發現了代表ecls的hexnumbers的一些信息,但現在我找不到它了。但是我嘗試了這些hexnumbers,因爲QRcode上的ecl-bit會相應地改變。所以我假設這些數字是正確的(1 =低,0 =中,2 =高,3 =四分位數)。

下面是QRCode與Level.FBits的示例:= 2,這意味着我希望ecl爲「高」。內容是「Hello world」。中間的交叉圖像是我必須實現的標準[原文]的一部分,所以不要問這個問題。 enter image description here

有沒有人有任何想法如何解決這個問題?我試過......嗯......我試着去理解代碼,但它太多了。我無法修復它。如果我無法通過其他人修復它,我將不得不... ...找到另一個解決方案。這將是一個問題。

回答

2

已解決。見下面的代碼。方法GenerateQRCode()現在需要ErrorCorrectionLevel的一個參數:整數0-3。似乎工作。我必須刪除一些不變的行,因爲該文件對於StackOverflow來說太大。合併自己。

unit DelphiZXingQRCode; 

    // ZXing QRCode port to Delphi, by Debenu Pty Ltd 
    // www.debenu.com 

    // Original copyright notice 
    (* 
    * Copyright 2008 ZXing authors 
    * 
    * Licensed under the Apache License, Version 2.0 (the "License"); 
    * you may not use this file except in compliance with the License. 
    * You may obtain a copy of the License at 
    * 
    *  http://www.apache.org/licenses/LICENSE-2.0 
    * 
    * Unless required by applicable law or agreed to in writing, software 
    * distributed under the License is distributed on an "AS IS" BASIS, 
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
    * See the License for the specific language governing permissions and 
    * limitations under the License. 
    *) 

    interface 

    type 
     TQRCodeEncoding = (qrAuto, qrNumeric, qrAlphanumeric, qrISO88591, qrUTF8NoBOM, qrUTF8BOM); 
     T2DBooleanArray = array of array of Boolean; 

     TDelphiZXingQRCode = class 
     protected 
     FData: WideString; 
     FRows: Integer; 
     FColumns: Integer; 
     FEncoding: TQRCodeEncoding; 
     FQuietZone: Integer; 
     FElements: T2DBooleanArray; 
     FErrorCorrectionLevel: integer; 
     procedure SetEncoding(NewEncoding: TQRCodeEncoding); 
     procedure SetData(const NewData: WideString); 
     procedure SetQuietZone(NewQuietZone: Integer); 
     procedure SetErrorCorrectionLevel(value: integer); 
     function GetIsBlack(Row, Column: Integer): Boolean; 
     procedure Update; 
     public 
     constructor Create; 
     property Data: WideString read FData write SetData; 
     property Encoding: TQRCodeEncoding read FEncoding write SetEncoding; 
     property ErrorCorrectionLevel: integer read fErrorCorrectionLevel write SetErrorCorrectionLevel; 
     property QuietZone: Integer read FQuietZone write SetQuietZone; 
     property Rows: Integer read FRows; 
     property Columns: Integer read FColumns; 
     property IsBlack[Row, Column: Integer]: Boolean read GetIsBlack; 
     end; 

    implementation 

    uses 
     SysUtils, 
     contnrs, Math, Classes; 

    type 
     TByteArray = array of Byte; 
     T2DByteArray = array of array of Byte; 
     TIntegerArray = array of Integer; 

    // File too large for Stackoverflow: Deleted unchanged lines. 

    { TErrorCorrectionLevel } 

    procedure TErrorCorrectionLevel.Assign(Source: TErrorCorrectionLevel); 
    begin 
     Self.fOrdinal := Source.FOrdinal; 
    end; 

    constructor TErrorCorrectionLevel.Create(ordinalValue: integer); 
    begin 

     fOrdinal:=0; 
     if (ordinalValue >= 0) and (ordinalValue <=3) then 
     fOrdinal:=ordinalValue; 
    end; 

    function TErrorCorrectionLevel.GetBits: integer; 
    begin 
     if fOrdinal = 0 then // level L 
     result:=1 
     else 
     if fOrdinal = 1 then // level M 
     result:=0 
     else 
     if fOrdinal = 2 then // level Q 
     result:=3 
     else 
     if fOrdinal = 3 then // level H 
     result:=2 
     else 
     result:=1; 
    end; 


    // File too large for Stackoverflow: Deleted unchanged lines. 

    procedure TDelphiZXingQRCode.SetErrorCorrectionLevel(value: integer); 
    begin 
     if (value < 0) or (value > 3) then 
     raise Exception.Create('invalid error correction value. must be in range 0..3.'); 

     if value <> fErrorCorrectionLevel then 
     begin 
     FErrorCorrectionLevel:=value; 
     Update; 
     end; 
    end; 

    procedure TDelphiZXingQRCode.SetQuietZone(NewQuietZone: Integer); 
    begin 
     if ((FQuietZone <> NewQuietZone) and (NewQuietZone >= 0) and (NewQuietZone <= 100)) then 
     begin 
     FQuietZone := NewQuietZone; 
     Update; 
     end; 
    end; 

    procedure TDelphiZXingQRCode.Update; 
    begin 
     FElements := GenerateQRCode(FData, Ord(FEncoding), FErrorCorrectionLevel); 
     FRows := Length(FElements) + FQuietZone * 2; 
     FColumns := FRows; 
    end; 
    end. 
+1

它的工作原理,但你必須自己猜測一些變化。無論如何,感謝修復,你可以向上遊發送嗎? –