QRGenerator icon indicating copy to clipboard operation
QRGenerator copied to clipboard

QR Correction Level Support

Open gerkata21 opened this issue 2 months ago • 0 comments

Currently there is not support to be able to set the QR correction level, Would it be possible to add this please find proposed solution

   public enum ErrorCorrection {
       LOW,
       MEDIUM,
       QUARTILE,
       HIGH
   }
    private ErrorCorrectionLevel getCorrectionLevel(ErrorCorrection errorCorrectionLevel) {
        switch (errorCorrectionLevel) {
            case LOW:
                return ErrorCorrectionLevel.L;
            case MEDIUM:
                return ErrorCorrectionLevel.M;
            case QUARTILE:
                return ErrorCorrectionLevel.Q;
            case HIGH:
                return ErrorCorrectionLevel.H;
            default:
                throw new IllegalArgumentException("Unknown error correction level: " + errorCorrectionLevel);
        }
    }
    public Bitmap getBitmap(int margin) {
        return getBitmap(margin, null);
    }

    public Bitmap getBitmap(int margin, ErrorCorrection errorCorrectionLevel) {
        ....
            if (encoding != null) {
                hints.put(EncodeHintType.CHARACTER_SET, encoding);
            }
            
            if (errorCorrectionLevel != null) {
                hints.put(EncodeHintType.ERROR_CORRECTION, getCorrectionLevel(errorCorrectionLevel));
            }
    
            hints.put(EncodeHintType.MARGIN, margin);
       ....
    }

gerkata21 avatar Dec 13 '24 15:12 gerkata21