コード例 #1
0
        // public ByteMatrix encode(System.String contents, BarcodeFormat format, int width, int height, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com)
        public ByteMatrix encode(System.String contents, BarcodeFormat format, int width, int height, System.Collections.Generic.Dictionary <Object, Object> hints) // added by .net follower (http://dotnetfollower.com)
        {
            if (contents == null || contents.Length == 0)
            {
                throw new System.ArgumentException("Found empty contents");
            }

            if (format != BarcodeFormat.QR_CODE)
            {
                throw new System.ArgumentException("Can only encode QR_CODE, but got " + format);
            }

            if (width < 0 || height < 0)
            {
                throw new System.ArgumentException("Requested dimensions are too small: " + width + 'x' + height);
            }

            ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;

            if (hints != null)
            {
                // ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints[EncodeHintType.ERROR_CORRECTION]; // commented by .net follower (http://dotnetfollower.com)
                ErrorCorrectionLevel requestedECLevel = hints.ContainsKey(EncodeHintType.ERROR_CORRECTION) ? (ErrorCorrectionLevel)hints[EncodeHintType.ERROR_CORRECTION] : null; // added by .net follower (http://dotnetfollower.com)
                if (requestedECLevel != null)
                {
                    errorCorrectionLevel = requestedECLevel;
                }
            }

            QRCode code = new QRCode();

            Encoder.encode(contents, errorCorrectionLevel, hints, code);
            return(renderResult(code, width, height));
        }
コード例 #2
0
ファイル: QRCodeWriter.cs プロジェクト: leconer/BarCodeSharp
        public ByteMatrix encode(System.String contents, BarcodeFormat format, int width, int height, System.Collections.Hashtable hints)
        {
            if (contents == null || contents.Length == 0)
            {
                throw new System.ArgumentException("Found empty contents");
            }

            if (format != BarcodeFormat.QR_CODE)
            {
                throw new System.ArgumentException("Can only encode QR_CODE, but got " + format);
            }

            if (width < 0 || height < 0)
            {
                throw new System.ArgumentException("Requested dimensions are too small: " + width + 'x' + height);
            }

            ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;

            if (hints != null)
            {
                ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel)hints[EncodeHintType.ERROR_CORRECTION];
                if (requestedECLevel != null)
                {
                    errorCorrectionLevel = requestedECLevel;
                }
            }

            QRCode code = new QRCode();

            Encoder.encode(contents, errorCorrectionLevel, hints, code);
            return(renderResult(code, width, height));
        }
コード例 #3
0
        public ByteMatrix encode(string contents, BarcodeFormat format, int width, int height, System.Collections.Generic.Dictionary <Object, Object> hints)
        {
            if (contents == null || contents.Length == 0)
            {
                throw new System.ArgumentException("Found empty contents");
            }

            if (format != BarcodeFormat.QR_CODE)
            {
                throw new System.ArgumentException("Can only encode QR_CODE, but got " + format);
            }

            if (width < 0 || height < 0)
            {
                throw new System.ArgumentException("Requested dimensions are too small: " + width + 'x' + height);
            }

            ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;

            if (hints != null && hints.ContainsKey(EncodeHintType.ERROR_CORRECTION))
            {
                errorCorrectionLevel = (ErrorCorrectionLevel)hints[EncodeHintType.ERROR_CORRECTION]; //UPGRADE: Fixed dictionary key grab issue
            }

            QRCode code = new QRCode();

            Encoder.encode(contents, errorCorrectionLevel, hints, code);
            return(renderResult(code, width, height));
        }