ClassLibraryWeiBao/QR二维码/QrEncoder.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;

namespace Gma.QrCodeNet.Encoding
{
    public class QrEncoder
    {
        public ErrorCorrectionLevel ErrorCorrectionLevel { get; set; }

        /// <summary>
        /// Default QrEncoder will set ErrorCorrectionLevel as M
        /// </summary>
        public QrEncoder()
            : this(ErrorCorrectionLevel.M)
        {

        }

        /// <summary>
        /// QrEncoder with parameter ErrorCorrectionLevel. 
        /// </summary>
        /// <param name="errorCorrectionLevel"></param>
        public QrEncoder(ErrorCorrectionLevel errorCorrectionLevel)
        {
            ErrorCorrectionLevel = errorCorrectionLevel;
        }

        /// <summary>
        /// Encode string content to QrCode matrix
        /// </summary>
        /// <exception cref="InputOutOfBoundaryException">
        /// This exception for string content is null, empty or too large</exception>
        public QrCode Encode(string content)
        {
        	if(string.IsNullOrEmpty(content))
        	{
        		throw new InputOutOfBoundaryException("Input should not be empty or null");
        	}
        	else
        		return new QrCode(QRCodeEncode.Encode(content, ErrorCorrectionLevel));
        }
        
        /// <summary>
        /// Try to encode content
        /// </summary>
        /// <returns>False if input content is empty, null or too large.</returns>
        public bool TryEncode(string content, out QrCode qrCode)
        {
        	try
        	{
        		qrCode = this.Encode(content);
        		return true;
        	}
        	catch(InputOutOfBoundaryException)
        	{
        		qrCode = new QrCode();
        		return false;
        	}
        }

后面还有 35 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。