private void btnEncode_Click_1(object sender, EventArgs e)
        {
            if (txtEncodeData.Text.Trim() == String.Empty)
            {
                MessageBox.Show("Data must not be empty.");
                return;
            }

            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            String encoding = cboEncoding.Text;
            if (encoding == "Byte")
            {
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            }
            else if (encoding == "AlphaNumeric")
            {
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC;
            }
            else if (encoding == "Numeric")
            {
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.NUMERIC;
            }

            try
            {
                int scale = Convert.ToInt16(txtSize.Text);
                qrCodeEncoder.QRCodeScale = scale;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Invalid size!");
                return;
            }

            try
            {
                int version = Convert.ToInt16(cboVersion.Text);
                qrCodeEncoder.QRCodeVersion = version;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Invalid version !");
            }

            string errorCorrect = cboCorrectionLevel.Text;
            if (errorCorrect == "L")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L;
            else if (errorCorrect == "M")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
            else if (errorCorrect == "Q")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.Q;
            else if (errorCorrect == "H")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;

            string data = txtEncodeData.Text;
            var encodedData = qrCodeEncoder.Encode(data);
            var qrImage = new QrImage();
            Image image = qrImage.CreateImage(encodedData);
            picEncode.Image = image;
        }
Exemple #2
1
        public ActionResult CreateCode_Choose(string strData, string qrEncoding, string level, int version, int scale)
        {
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            string encoding = qrEncoding;
            switch (encoding)
            {
                case "Byte":
                    qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
                    break;
                case "AlphaNumeric":
                    qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC;
                    break;
                case "Numeric":
                    qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.NUMERIC;
                    break;
                default:
                    qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
                    break;
            }

            qrCodeEncoder.QRCodeScale = scale;
            qrCodeEncoder.QRCodeVersion = version;
            switch (level)
            {
                case "L":
                    qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L;
                    break;
                case "M":
                    qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
                    break;
                case "Q":
                    qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.Q;
                    break;
                default:
                    qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;
                    break;
            }
            //文字生成图片
            Image image = qrCodeEncoder.Encode(strData);
            string filename = DateTime.Now.ToString("yyyymmddhhmmssfff").ToString() + ".jpg";
            string strDir = Server.MapPath(@"~\Upload");
            string filePath = strDir + "\\" + filename;
            //如果文件夹不存在,则创建
            if (!Directory.Exists(strDir))
                Directory.CreateDirectory(strDir);
            System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
            image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
            fs.Close();
            image.Dispose();
            return Content(@"/Upload/" + filename);
        }
Exemple #3
1
        public static Bitmap GetqrCode(int i, string content)
        {
            Bitmap bt;
            string enCodeString = content;
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            qrCodeEncoder.QRCodeVersion = i;
            qrCodeEncoder.QRCodeScale = 4;
            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;

            bt = qrCodeEncoder.Encode(enCodeString, Encoding.UTF8);

               return bt;
        }
 public QRCode(string data, string title)
 {
     InitializeComponent();
     textBox.Text = data;
     Title = title;
     var qrCodeEncoder = new QRCodeEncoder();
     qrCodeEncoder.QRCodeScale = 16;
     var image = qrCodeEncoder.Encode(data, Encoding.UTF8);
     var imageSrc = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
        image.GetHbitmap(),
        IntPtr.Zero,
        Int32Rect.Empty,
        BitmapSizeOptions.FromWidthAndHeight(image.Width, image.Height));
     imgBox.Source = imageSrc;
 }
Exemple #5
1
 public Bitmap CreateImgCode(string htmlUrl, int size = 4)
 {
     //创建二维码生成类
     QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
     //设置编码模式
     qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
     //设置编码测量度
     qrCodeEncoder.QRCodeScale = size;
     //设置编码版本
     qrCodeEncoder.QRCodeVersion = 7;
     //设置编码错误纠正
     qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
     //生成二维码图片
     return qrCodeEncoder.Encode(CreateQRCode(htmlUrl));
 }
Exemple #6
0
        /// <summary>
        /// 编码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text != "")
            {
                Cursor.Current = Cursors.WaitCursor;
                if (textBox1.Text.Trim() == String.Empty)
                {
                    MessageBox.Show("不能为空.");
                    return;
                }
                QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
                qrCodeEncoder.QRCodeScale = 4;
                qrCodeEncoder.QRCodeVersion = 7;
               qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
                System.Drawing.Image image;
                String data = textBox1.Text;
                //编码
                //string code = Server.UrlEncode(this.txtSourc.Text.Trim().ToString());
                image = qrCodeEncoder.Encode(data,Encoding.UTF8);
                //图片显示
                this.pictureBox1.Image = image;
                Cursor.Current = Cursors.Default;

            }
        }
        public static void ShowSignCheck(Guid notaryId, byte[] code)
        {
            string url = string.Format(
            "https://pivote.piratenpartei.ch/set.aspx?id={0}&c={1}",
            notaryId.ToString(),
            code.ToHexString());

              GenerateSignCheckDialog dialog = new GenerateSignCheckDialog();
              dialog.browseLink.Text = url;

              QRCodeEncoder qrEncoder = new QRCodeEncoder();
              qrEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
              qrEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L;
              qrEncoder.QRCodeVersion = 7;
              qrEncoder.QRCodeScale = 10;

              Image qrImage = qrEncoder.Encode(url);;
              var image = new Bitmap(qrImage.Width / 4 * 6, qrImage.Height / 4 * 6);
              var graphics = Graphics.FromImage(image);
              graphics.Clear(Color.White);
              graphics.DrawImage(qrImage, (float)qrImage.Width / 4f, (float)qrImage.Height / 4f);
              graphics.Flush();
              dialog.qrCodeImage.Image = image;

              dialog.ShowDialog();
        }
Exemple #8
0
        /// <summary>
        /// 生成二维码
        /// </summary>
        /// <param name="qrCodeContent">要编码的内容</param>
        /// <returns>返回二维码位图</returns>
        public static string QRCodeEncoderUtil(string qrCodeContent)
        {
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            qrCodeEncoder.QRCodeVersion = 0;
            if (!(qrCodeContent.Contains("http://") || qrCodeContent.Contains("https://")))
                qrCodeContent = "https://" + qrCodeContent;
            Bitmap img = qrCodeEncoder.Encode(qrCodeContent,Encoding.UTF8); //指定UTF8编码,支持中文
            string str =System.Web.HttpContext.Current.Server.MapPath("~");

            //存储本地路径
            string name = DateTime.Now.Millisecond.ToString();
            StringBuilder sbuilder = new StringBuilder();
            sbuilder.Append(str);
            sbuilder.Append(@"\images\");
            sbuilder.Append("QR" + name + ".jpg");
            img.Save(sbuilder.ToString());

            //获取服务器路径
            HttpRequest req = HttpContext.Current.Request;
            string serverpath = req.ServerVariables["SERVER_NAME"];
            if (req.ServerVariables["SERVER_PORT"] != null && !"".Equals(req.ServerVariables["SERVER_PORT"]) && !"80".Equals(req.ServerVariables["SERVER_PORT"]))
            {
                serverpath += ":" + req.ServerVariables["SERVER_PORT"];
            }
            //return System.Web.HttpContext.Current.Server.MapPath("/Images/QR" + name + ".jpg"); 返回的还是物理路径
            return "http://" + serverpath + "/Images/QR"+name+".jpg";
        }
Exemple #9
0
        public ActionResult GetQRCode(string str)
        {
            HttpContextBase context = this.HttpContext;
            if(string.IsNullOrEmpty(str))str = context.Request.ServerVariables["HTTP_REFERER"];
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;

            qrCodeEncoder.QRCodeScale = 4;

            qrCodeEncoder.QRCodeVersion = 7;

            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;

            System.Drawing.Bitmap bmp;
            String data = str;
            bmp = qrCodeEncoder.Encode(data);

            MemoryStream ms = new MemoryStream();
            try
            {
                bmp.Save(ms, ImageFormat.Png);
            }
            finally
            {
                //显式释放资源
                bmp.Dispose();
                ms.Dispose();
            }
            byte[] bytes = ms.ToArray();
            return File(bytes, @"image/png");
        }
Exemple #10
0
    /*
     * 
     * CREATE  PROCEDURE [dbo].[ProcCustomPage]
		(
		    @Table_Name               varchar(5000),      	    --表名
		    @Sign_Record              varchar(50),       		--主键
		    @Filter_Condition         varchar(1000),     	    --筛选条件,不带where
		    @Page_Size                int,               		--页大小
		    @Page_Index               int,          			--页索引     			
	        @TaxisField               varchar(1000),            --排序字段
		    @Taxis_Sign               int,               		--排序方式 1为 DESC, 0为 ASC
            @Find_RecordList          varchar(1000),        	--查找的字段
		    @Record_Count             int                		--总记录数
		 )
		 AS
			BEGIN 
			DECLARE  @Start_Number          int
			DECLARE  @End_Number            int
			DECLARE  @TopN_Number           int
		 DECLARE  @sSQL                  varchar(8000)
                 if(@Find_RecordList='')
                 BEGIN
                      SELECT @Find_RecordList='*'
                 END
		 SELECT @Start_Number =(@Page_Index-1) * @Page_Size
			IF @Start_Number<=0
		 SElECT @Start_Number=0
			SELECT @End_Number=@Start_Number+@Page_Size
			IF @End_Number>@Record_Count
		 SELECT @End_Number=@Record_Count
		 SELECT @TopN_Number=@End_Number-@Start_Number
		 IF @TopN_Number<=0
		 SELECT @TopN_Number=0
			print @TopN_Number
		 print @Start_Number
		 print @End_Number
		 print @Record_Count
                 IF @TaxisField=''
                 begin
                    select  @TaxisField=@Sign_Record
                 end
		 IF @Taxis_Sign=0
		  	BEGIN
		 		IF @Filter_Condition=''
				 BEGIN
		 			SELECT @sSQL='SELECT '+@Find_RecordList+' FROM '+@Table_Name+' 
		     			WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@TopN_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+' 
		    			 WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@End_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+' 
		    		 ORDER BY '+@TaxisField+') order by '+@TaxisField+' DESC)order by '+@TaxisField
		 		END
				ELSE
				BEGIN
				SELECT @sSQL='SELECT '+@Find_RecordList+' FROM '+@Table_Name+' 
		     WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@TopN_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+' 
		     WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@End_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+' 
		     WHERE '+@Filter_Condition+' ORDER BY '+@TaxisField+') and '+@Filter_Condition+' order by '+@TaxisField+' DESC) and '+@Filter_Condition+' order by '+@TaxisField
				 END
			END
		ELSE
			BEGIN
			IF @Filter_Condition=''
				BEGIN
					SELECT @sSQL='SELECT '+@Find_RecordList+' FROM '+@Table_Name+' 
		         WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@TopN_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+' 
		         WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@End_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+' 
		         ORDER BY '+@TaxisField+' DESC) order by '+@TaxisField+')order by '+@TaxisField+' DESC'
		     END
			ELSE
			BEGIN
				SELECT @sSQL='SELECT '+@Find_RecordList+' FROM '+@Table_Name+' 
		     WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@TopN_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+' 
		     WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@End_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+' 
		     WHERE '+@Filter_Condition+' ORDER BY '+@TaxisField+' DESC) and '+@Filter_Condition+' order by '+@TaxisField+') and '+@Filter_Condition+' order by '+@TaxisField+' DESC'
		 END
			END
			EXEC (@sSQL)
			IF @@ERROR<>0
			RETURN -3              
		 RETURN 0
		 END
		 
		 PRINT  @sSQL
        GO

     * */


    #endregion

    #region SQL2005 分页存储过程
    /*
     * 
   CREATE PROCEDURE [dbo].[GetRecordFromPage] 
    @SelectList            VARCHAR(2000),    --欲选择字段列表
    @TableSource        VARCHAR(100),    --表名或视图表 
    @SearchCondition    VARCHAR(2000),    --查询条件
    @OrderExpression    VARCHAR(1000),    --排序表达式
    @PageIndex            INT = 1,        --页号,从0开始
    @PageSize            INT = 10        --页尺寸
AS 
BEGIN
    IF @SelectList IS NULL OR LTRIM(RTRIM(@SelectList)) = ''
    BEGIN
        SET @SelectList = '*'
    END
    PRINT @SelectList
    
    SET @SearchCondition = ISNULL(@SearchCondition,'')
    SET @SearchCondition = LTRIM(RTRIM(@SearchCondition))
    IF @SearchCondition <> ''
    BEGIN
        IF UPPER(SUBSTRING(@SearchCondition,1,5)) <> 'WHERE'
        BEGIN
            SET @SearchCondition = 'WHERE ' + @SearchCondition
        END
    END
    PRINT @SearchCondition

    SET @OrderExpression = ISNULL(@OrderExpression,'')
    SET @OrderExpression = LTRIM(RTRIM(@OrderExpression))
    IF @OrderExpression <> ''
    BEGIN
        IF UPPER(SUBSTRING(@OrderExpression,1,5)) <> 'WHERE'
        BEGIN
            SET @OrderExpression = 'ORDER BY ' + @OrderExpression
        END
    END
    PRINT @OrderExpression

    IF @PageIndex IS NULL OR @PageIndex < 1
    BEGIN
        SET @PageIndex = 1
    END
    PRINT @PageIndex
    IF @PageSize IS NULL OR @PageSize < 1
    BEGIN
        SET @PageSize = 10
    END
    PRINT  @PageSize

    DECLARE @SqlQuery VARCHAR(4000)

    SET @SqlQuery='SELECT '+@SelectList+',RowNumber 
    FROM 
        (SELECT ' + @SelectList + ',ROW_NUMBER() OVER( '+ @OrderExpression +') AS RowNumber 
          FROM '+@TableSource+' '+ @SearchCondition +') AS RowNumberTableSource 
    WHERE RowNumber BETWEEN ' + CAST(((@PageIndex - 1)* @PageSize+1) AS VARCHAR) 
    + ' AND ' + 
    CAST((@PageIndex * @PageSize) AS VARCHAR) 
--    ORDER BY ' + @OrderExpression
    PRINT @SqlQuery
    SET NOCOUNT ON
    EXECUTE(@SqlQuery)
    SET NOCOUNT OFF
 
    RETURN @@RowCount
END
     **/

    #endregion

    #endregion

    public static void create_two(string nr, string regno)
    {

        System.Drawing.Bitmap bt;

        string enCodeString = nr;

        ThoughtWorks.QRCode.Codec.QRCodeEncoder qrCodeEncoder = new ThoughtWorks.QRCode.Codec.QRCodeEncoder();
        qrCodeEncoder.QRCodeScale = 15;
        qrCodeEncoder.QRCodeVersion = 10;
        bt = qrCodeEncoder.Encode(enCodeString, Encoding.UTF8);

        //bt = qrCodeEncoder.Encode(enCodeString, Encoding.GetEncoding("gb18030"));
        //string filename = string.Format(DateTime.Now.ToString(), regno) + ".jpg";
        string filename = regno;
        filename = filename.Replace(" ", "");

        filename = filename.Replace(":", "");

        filename = filename.Replace("-", "");

        filename = filename.Replace(".", "");
        HttpServerUtility su = HttpContext.Current.Server;
        bt.Save(su.MapPath("../QRcode/") + filename + ".png");

    }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["data"]))
            {
                string str = Request.QueryString["data"];

                //初始化二维码生成工具
                QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
                qrCodeEncoder.QRCodeVersion = 0;
                qrCodeEncoder.QRCodeScale = 4;

                //将字符串生成二维码图片
                Bitmap image = qrCodeEncoder.Encode(str, Encoding.Default);

                //保存为PNG到内存流
                MemoryStream ms = new MemoryStream();
                image.Save(ms, ImageFormat.Png);

                //输出二维码图片
                Response.BinaryWrite(ms.GetBuffer());
                Response.End();
            }
        }
 /// <summary>
 /// 生成二维码,如果有Logo,则在二维码中添加Logo
 /// </summary>
 /// <param name="content"></param>
 /// <returns></returns>
 public Bitmap CreateQRCode(string content)
 {
     QRCodeEncoder qrEncoder = new QRCodeEncoder();
     qrEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
     qrEncoder.QRCodeScale = Convert.ToInt32(txtSize.Text);
     qrEncoder.QRCodeVersion = Convert.ToInt32(cboVersion.SelectedValue);
     qrEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
     try
     {
         Bitmap qrcode = qrEncoder.Encode(content, Encoding.UTF8);
         if (!logoImagepath.Equals(string.Empty))
         {
             Graphics g = Graphics.FromImage(qrcode);
             Bitmap bitmapLogo = new Bitmap(logoImagepath);
             int logoSize = Convert.ToInt32(txtLogoSize.Text);
             bitmapLogo = new Bitmap(bitmapLogo, new System.Drawing.Size(logoSize, logoSize));
             PointF point = new PointF(qrcode.Width / 2 - logoSize / 2, qrcode.Height / 2 - logoSize / 2);
             g.DrawImage(bitmapLogo, point);
         }
         return qrcode;
     }
     catch (IndexOutOfRangeException ex)
     {
         MessageBox.Show("超出当前二维码版本的容量上限,请选择更高的二维码版本!", "系统提示");
         return new Bitmap(100, 100);
     }
     catch (Exception ex)
     {
         MessageBox.Show("生成二维码出错!", "系统提示");
         return new Bitmap(100, 100);
     }
 }
Exemple #13
0
        /// <summary>
        /// 生成二维码
        /// </summary>
        /// <param name="data">数据</param>
        /// <param name="filePath">文件保存路径(绝对路径)</param>
        /// <param name="hasLogo">二维码图标是否添加图片</param>
        /// <param name="logoFilePath">图片的路径(绝对路径)</param>
        /// <returns>true--成功;false--失败</returns>
        public static bool CreateQRcode(string data, string filePath, bool hasLogo = false, string logoFilePath = "")
        {
            bool result = false;
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;//二维码编码(Byte、AlphaNumeric、Numeric)
            qrCodeEncoder.QRCodeScale = 50;//二维码尺寸(Version为0时,1:26x26,每加1宽和高各加25
            qrCodeEncoder.QRCodeVersion = 10;//二维码密集度0-40
            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;//二维码纠错能力(L:7% M:15% Q:25% H:30%)
            try
            {
                Image card = qrCodeEncoder.Encode(data, Encoding.UTF8);

                using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    card.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
                    fs.Close();
                }

                if (hasLogo)
                {
                    AddLogo(logoFilePath, card, filePath);
                }

                card.Dispose();
                result = true;
            }
            catch (Exception ex)
            {
                result = false;
            }
            return result;
        }
Exemple #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (txtEncodeData.Text.Trim() == String.Empty)
            {
                MessageBox.Show("Data must not be empty.");
                return;
            }

            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            String encoding = cboEncoding.Text;
            if (encoding == "Byte")
            {
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            }
            else if (encoding == "AlphaNumeric")
            {
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC;
            }
            else if (encoding == "Numeric")
            {
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.NUMERIC;
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE;
            }
            try
            {
                int scale = Convert.ToInt16(txtSize.Text);
                qrCodeEncoder.QRCodeScale = scale;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Invalid size!");
                return;
            }
            try
            {
                int version = Convert.ToInt16(cboVersion.Text);
                qrCodeEncoder.QRCodeVersion = version;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Invalid version !");
            }

            string errorCorrect = cboCorrectionLevel.Text;
            if (errorCorrect == "L")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L;
            else if (errorCorrect == "M")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
            else if (errorCorrect == "Q")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.Q;
            else if (errorCorrect == "H")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;

            qrCodeEncoder.QRCodeBackgroundColor = System.Drawing.Color.DeepSkyBlue;
            //qrCodeEncoder.
            Image image;
            String data = txtEncodeData.Text;
            image = qrCodeEncoder.Encode(data);
            pb_view.Image = image;
        }
        /*生成QR码 GuidToQRCode(string sGuid)*/

        public Image GuidToQRCode(string sGuid) {
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            Image image = qrCodeEncoder.Encode(sGuid);

            return image;
        }
        private Bitmap CreatQRCode(string qrCodeContent)
        {
            Bitmap bt;
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; //  support different mode
            qrCodeEncoder.QRCodeScale = 10;
            qrCodeEncoder.QRCodeVersion = 0;
            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;

            //动态调整二维码版本号,上限40,过长返回空白图片,编码后字符最大字节长度2953
            while (true)
            {
                try
                {
                    bt = qrCodeEncoder.Encode(qrCodeContent, System.Text.Encoding.UTF8);
                    break;
                }
                catch (IndexOutOfRangeException e)
                {
                    if (qrCodeEncoder.QRCodeVersion < 40)
                    {
                        qrCodeEncoder.QRCodeVersion++;
                    }
                    else
                    {
                        bt = new Bitmap(100, 100);
                        break;
                    }
                }
            }

            return bt;
        }
Exemple #17
0
        /// <summary>
        /// 生成二维码图片
        /// </summary>
        /// <param name="str">字符串</param>
        /// <param name="size">图片大小</param>
        /// <param name="path">图片位置 
        /// 例如  /abc/abc/
        /// </param>
        /// <returns>返回生成的二维码图片路径</returns>
        public string Create(string str, int size, string path)
        {
            try
            {
                QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
                //设置编码模式
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
                //设置编码测量度
                qrCodeEncoder.QRCodeScale = size;
                //设置编码版本
                qrCodeEncoder.QRCodeVersion = 8;
                //设置编码错误纠正
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
                System.Drawing.Image image = qrCodeEncoder.Encode(str);

                string filename = "~" + path + Guid.NewGuid() + ".jpg";
                image.Save(HttpContext.Current.Request.MapPath(filename));

                return filename.Replace("~", "");
            }
            catch (Exception)
            {
                return "";
            }

        }
Exemple #18
0
        private void GenerateQRCode()
        {
            try
            {
                var url = "http://" + Request.Url.Authority + "/Index.aspx?rid=" + this.ddlRestaurant.SelectedValue + "&tid=" + this.hTableId.Value;

                var encoder = new QRCodeEncoder();
                encoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
                encoder.QRCodeScale = 8;
                encoder.QRCodeVersion = 7;
                encoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;

                using (var ms = new MemoryStream())
                {
                    using (Bitmap bmp = encoder.Encode(url))
                    {
                        bmp.Save(ms, ImageFormat.Jpeg);
                        Response.ClearContent();
                        Response.ContentEncoding = Encoding.UTF8;
                        Response.ContentType = "image/jpeg";
                        Response.AppendHeader("Content-Disposition", "attachment; filename=QRcode.jpg");
                        Response.BinaryWrite(ms.ToArray());
                        Response.Flush();
                        Response.End();
                    }
                }

            }
            catch (Exception ex)
            {
                this.lMsg.InnerText = "生成二维码失败,原因:" + ex.ToString();
            }
        }
        public void TestMethod1()
        {
            var encoder = new QRCodeEncoder();
            var content = "QR.NET https://github.com/aaronogan/QR.NET";

            var result = encoder.Encode(content);

            AssertMatrix(result);
        }
        public static Image GetQRImage(string url)
        {
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            qrCodeEncoder.QRCodeScale = 5;
            qrCodeEncoder.QRCodeVersion = 7;
            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;

            return qrCodeEncoder.Encode(url);
        }
Exemple #21
0
 /// <summary>
 /// 生成二维码
 /// </summary>
 /// <param name="data">生成内容</param>
 /// <returns>图片</returns>
 public static System.Drawing.Image AutoCreateQRcode(string data)
 {
     QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
     qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
     qrCodeEncoder.QRCodeScale = 4;
     qrCodeEncoder.QRCodeVersion = Convert.ToInt16(7);
     qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;
     string filename = DateTime.Now.ToString("yyyy-MM-ddhhmmss") + ".png";
     Bitmap bm = qrCodeEncoder.Encode(data);
     return bm;
 }
Exemple #22
0
        private void CreateQRCode(string url)
        {
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();

            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            qrCodeEncoder.QRCodeScale = 4;
            qrCodeEncoder.QRCodeVersion = 7;
            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;

            imageQRCode.Image = qrCodeEncoder.Encode(url);
        }
Exemple #23
0
 protected QRVerToDataSize(int version,
         QRCodeEncoder.ERROR_CORRECTION errorCorrect,
         int numeric,
         int alphaNumeric,
         int @byte)
 {
     Version = version;
     ErrorCorrect = errorCorrect;
     Numeric = numeric;
     AlphaNumeric = alphaNumeric;
     Byte = @byte;
 }
Exemple #24
0
 /// <summary>
 /// 自动创建二维码
 /// </summary>
 /// <param name="content">二维码内容</param>
 /// <returns></returns>
 public static byte[] AutoCreateQRCode(string content)
 {
     QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
     qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
     qrCodeEncoder.QRCodeScale = 4;
     qrCodeEncoder.QRCodeVersion = Convert.ToInt16(7);
     qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
     string filename = DateTime.Now.ToString("yyyy-MM-ddhhmmss") + ".png";
     Bitmap bm = qrCodeEncoder.Encode(content);
     MemoryStream ms = new MemoryStream();
     bm.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
     byte[] bytes = ms.ToArray();
     ms.Close();
     return bytes;
 }
Exemple #25
0
 public static Bitmap Create_ImgCode(string codeNumber, int size)
 {
     //创建二维码生成类
     QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
     //设置编码模式
     qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
     //设置编码测量度
     qrCodeEncoder.QRCodeScale = size;
     //设置编码版本
     qrCodeEncoder.QRCodeVersion = 0;
     //设置编码错误纠正
     qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
     //生成二维码图片
     System.Drawing.Bitmap image = qrCodeEncoder.Encode(codeNumber);
     return image;
 }
Exemple #26
0
        /// <summary>
        /// Encodes a QR code, making the best choice based on string length
        /// (apparently not provided by QR lib?)
        /// </summary>
        public static Bitmap EncodeQRCode(string what)
        {
            if (what == null || what == "") return null;

            // Determine if we can use alphanumeric encoding (e.g. public key hex)
            Regex r = new Regex("^[0-9A-F]{63,154}$");
            bool IsAlphanumeric = r.IsMatch(what);

            QRCodeEncoder qr = new QRCodeEncoder();
            if (IsAlphanumeric) {
                qr.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC;
                if (what.Length > 154) {
                    return null;
                } else if (what.Length > 67) {
                    // 5L is good to 154 alphanumeric characters
                    qr.QRCodeVersion = 5;
                    qr.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L;
                } else {
                    // 4Q is good to 67 alphanumeric characters
                    qr.QRCodeVersion = 4;
                    qr.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.Q;
                }
            } else {
                if (what.Length > 84) {
                    // We don't intend to encode any alphanumeric strings longer than confirmation codes at 75 characters
                    return null;
                } else if (what.Length > 62) {
                    // 5M is good to 84 characters
                    qr.QRCodeVersion = 5;
                    qr.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
                } else if (what.Length > 34) {
                    // 4M is good to 62 characters
                    qr.QRCodeVersion = 4;
                    qr.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
                } else if (what.Length > 32) {
                    // 4H is good to 34 characters
                    qr.QRCodeVersion = 4;
                    qr.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;
                } else {
                    // 3Q is good to 32 characters
                    qr.QRCodeVersion = 3;
                    qr.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.Q;
                }
            }

            return qr.Encode(what);
        }
Exemple #27
0
        private void txtPrintContentQRCode_TextChanged(object sender, TextChangedEventArgs e)
        {
            ThoughtWorks.QRCode.Codec.QRCodeEncoder encoder = new ThoughtWorks.QRCode.Codec.QRCodeEncoder();
            //encoder.QRCodeBackgroundColor = System.Drawing.Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);//白色
            encoder.QRCodeBackgroundColor = System.Drawing.Color.FromArgb(0x00, 0xBF, 0xBF, 0xBF); //和背景颜色一样的透明色
            encoder.QRCodeForegroundColor = System.Drawing.Color.FromArgb(0xFF, 0x00, 0x00, 0x00); //黑色
            //设置编码格式
            encoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;                             //编码方法
            //设置规模和版本
            encoder.QRCodeScale   = 9;                                                             //大小
            encoder.QRCodeVersion = 4;                                                             //版本
            //设置错误校验(错误更正)的级别
            encoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
            System.Drawing.Bitmap bp = encoder.Encode(tbxPrintContent.Text.ToString(), Encoding.GetEncoding("GB2312"));
            BitmapSource          bs = Imaging.CreateBitmapSourceFromHBitmap(bp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            imagePrintContentQRCode.Source = bs;
        }
        /// <summary>
        /// Procédure publique permettant de générer le QrCode contenant l'id du participant et de placer cette image dans le PictureBox présent dans l'interface de l'application 
        /// </summary>
        public void GenereQrCode()
        {
            // création et instanciation de l'objet QrCode
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            // paramètres de cet objet//
            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.NUMERIC;
            qrCodeEncoder.QRCodeScale = 4;
            qrCodeEncoder.QRCodeVersion = 7;
            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;

            System.Drawing.Image image;
            //donnée présente dans le QrCode(ici l'id du participant séléctionné dans le combobox)
            String data = CmbParticipant.SelectedValue.ToString();
            //on crée l'image contenant le QrCode
            image = qrCodeEncoder.Encode(data);
            //On place l'image crée dans le PictureBox situé dans l'interface de l'application
            picEncode.Image = image;
        }
Exemple #29
0
        private Image GetQRImage(string data)
        {
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();

            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;

            try
            {
                //14 2920bit/8=365byte 16 3624/8=453byte 18 4504=536byte 20 5352=669byte
                qrCodeEncoder.QRCodeScale = Int16.Parse(System.Configuration.ConfigurationManager.AppSettings["QRCodeScale"]);
            }
            catch (Exception ex)
            {

                qrCodeEncoder.QRCodeScale = 2;
            }

            try
            {
                //14 2920bit/8=365byte 16 3624/8=453byte 18 4504=536byte 20 5352=669byte
                qrCodeEncoder.QRCodeVersion = Int16.Parse(System.Configuration.ConfigurationManager.AppSettings["QRCodeVersion"]);
            }
            catch (Exception ex)
            {
                qrCodeEncoder.QRCodeVersion = 16;
            }

            string errorCorrect = "M";
            if (errorCorrect == "L")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L;
            else if (errorCorrect == "M")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
            else if (errorCorrect == "Q")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.Q;
            else if (errorCorrect == "H")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;

            Image image;
            //,System.Text.Encoding.UTF8
            int length = data.Length;
            image = qrCodeEncoder.Encode(data, System.Text.Encoding.GetEncoding("gb2312"));
            return image;
        }
 /// <summary>
 /// 生成二维码
 /// </summary>
 /// <param name="FileUpload_QRCode">上传图片控件</param>
 /// <param name="str">生成二维码网址</param>
 /// <param name="filename">保存二维码图片地址</param>
 /// <returns></returns>
 public static bool ToQRCode(FileUpload FileUpload_QRCode, string str, string filename)
 {
     QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
     qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
     qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
     qrCodeEncoder.QRCodeVersion = 8;
     qrCodeEncoder.QRCodeScale = 4;
     //二维码
     Bitmap image = qrCodeEncoder.Encode(str, Encoding.Default);
     if (FileUpload_QRCode.HasFile)
     {
         string CodeLogo = FileUpload_QRCode.FileName;
         MyHelper.SaveAs(FileUpload_QRCode, System.Web.HttpContext.Current.Server.MapPath("../upload/"), CodeLogo);
         System.Drawing.Image bt = CombinImage(image, System.Web.HttpContext.Current.Server.MapPath(string.Format("../upload/{0}", CodeLogo)));
     }
     //将image保存到filename
     image.Save(filename);
     return true;
 }
Exemple #31
0
 public void qrcodegenerator(string content, string from, string destination)
 {
     String data = content;
     if (!string.IsNullOrEmpty(data))
     {
         QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
         qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
         qrCodeEncoder.QRCodeScale = 4;
         qrCodeEncoder.QRCodeVersion = 8;
         qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
         System.Drawing.Image image = qrCodeEncoder.Encode(data);
         System.IO.MemoryStream MStream = new System.IO.MemoryStream();
         image.Save(MStream, System.Drawing.Imaging.ImageFormat.Png);
         System.IO.MemoryStream MStream1 = new System.IO.MemoryStream();
         CombinImage(image, from).Save(MStream1, System.Drawing.Imaging.ImageFormat.Png);
         Image img = System.Drawing.Image.FromStream(MStream1);
         img.Save(destination, ImageFormat.Jpeg);
     }
 }
Exemple #32
0
        public virtual bool[][] calQrcode(byte[] qrcodeData)
        {
            int dataCounter = 0;
            int dataLength  = qrcodeData.Length;

            int[]    dataValue = new int[dataLength + 32];
            sbyte[]  dataBits  = new sbyte[dataLength + 32];
            bool[][] result;
            if (dataLength <= 0)
            {
                bool[][] array    = new bool[1][];
                bool[][] arg_3B_0 = array;
                int      arg_3B_1 = 0;
                bool[]   array2   = new bool[1];
                arg_3B_0[arg_3B_1] = array2;
                bool[][] ret = array;
                result = ret;
            }
            else
            {
                if (this.qrcodeStructureappendN > 1)
                {
                    dataValue[0] = 3;
                    dataBits[0]  = 4;
                    dataValue[1] = this.qrcodeStructureappendM - 1;
                    dataBits[1]  = 4;
                    dataValue[2] = this.qrcodeStructureappendN - 1;
                    dataBits[2]  = 4;
                    dataValue[3] = this.qrcodeStructureappendParity;
                    dataBits[3]  = 8;
                    dataCounter  = 4;
                }
                dataBits[dataCounter] = 4;
                int[] codewordNumPlus;
                int   codewordNumCounterValue;
                switch (this.qrcodeEncodeMode)
                {
                case QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC:
                    codewordNumPlus = new int[]
                    {
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4
                    };
                    dataValue[dataCounter] = 2;
                    dataCounter++;
                    dataValue[dataCounter]  = dataLength;
                    dataBits[dataCounter]   = 9;
                    codewordNumCounterValue = dataCounter;
                    dataCounter++;
                    for (int i = 0; i < dataLength; i++)
                    {
                        char  chr      = (char)qrcodeData[i];
                        sbyte chrValue = 0;
                        if (chr >= '0' && chr < ':')
                        {
                            chrValue = (sbyte)(chr - '0');
                        }
                        else
                        {
                            if (chr >= 'A' && chr < '[')
                            {
                                chrValue = (sbyte)(chr - '7');
                            }
                            else
                            {
                                if (chr == ' ')
                                {
                                    chrValue = 36;
                                }
                                if (chr == '$')
                                {
                                    chrValue = 37;
                                }
                                if (chr == '%')
                                {
                                    chrValue = 38;
                                }
                                if (chr == '*')
                                {
                                    chrValue = 39;
                                }
                                if (chr == '+')
                                {
                                    chrValue = 40;
                                }
                                if (chr == '-')
                                {
                                    chrValue = 41;
                                }
                                if (chr == '.')
                                {
                                    chrValue = 42;
                                }
                                if (chr == '/')
                                {
                                    chrValue = 43;
                                }
                                if (chr == ':')
                                {
                                    chrValue = 44;
                                }
                            }
                        }
                        if (i % 2 == 0)
                        {
                            dataValue[dataCounter] = (int)chrValue;
                            dataBits[dataCounter]  = 6;
                        }
                        else
                        {
                            dataValue[dataCounter] = dataValue[dataCounter] * 45 + (int)chrValue;
                            dataBits[dataCounter]  = 11;
                            if (i < dataLength - 1)
                            {
                                dataCounter++;
                            }
                        }
                    }
                    dataCounter++;
                    break;

                case QRCodeEncoder.ENCODE_MODE.NUMERIC:
                    codewordNumPlus = new int[]
                    {
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        2,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4,
                        4
                    };
                    dataValue[dataCounter] = 1;
                    dataCounter++;
                    dataValue[dataCounter]  = dataLength;
                    dataBits[dataCounter]   = 10;
                    codewordNumCounterValue = dataCounter;
                    dataCounter++;
                    for (int i = 0; i < dataLength; i++)
                    {
                        if (i % 3 == 0)
                        {
                            dataValue[dataCounter] = (int)(qrcodeData[i] - 48);
                            dataBits[dataCounter]  = 4;
                        }
                        else
                        {
                            dataValue[dataCounter] = dataValue[dataCounter] * 10 + (int)(qrcodeData[i] - 48);
                            if (i % 3 == 1)
                            {
                                dataBits[dataCounter] = 7;
                            }
                            else
                            {
                                dataBits[dataCounter] = 10;
                                if (i < dataLength - 1)
                                {
                                    dataCounter++;
                                }
                            }
                        }
                    }
                    dataCounter++;
                    break;

                default:
                    codewordNumPlus = new int[]
                    {
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8,
                        8
                    };
                    dataValue[dataCounter] = 4;
                    dataCounter++;
                    dataValue[dataCounter]  = dataLength;
                    dataBits[dataCounter]   = 8;
                    codewordNumCounterValue = dataCounter;
                    dataCounter++;
                    for (int i = 0; i < dataLength; i++)
                    {
                        dataValue[i + dataCounter] = (int)(qrcodeData[i] & 255);
                        dataBits[i + dataCounter]  = 8;
                    }
                    dataCounter += dataLength;
                    break;
                }
                int totalDataBits = 0;
                for (int i = 0; i < dataCounter; i++)
                {
                    totalDataBits += (int)dataBits[i];
                }
                int ec;
                switch (this.qrcodeErrorCorrect)
                {
                case QRCodeEncoder.ERROR_CORRECTION.L:
                    ec = 1;
                    goto IL_3D0;

                case QRCodeEncoder.ERROR_CORRECTION.Q:
                    ec = 3;
                    goto IL_3D0;

                case QRCodeEncoder.ERROR_CORRECTION.H:
                    ec = 2;
                    goto IL_3D0;
                }
                ec = 0;
IL_3D0:
                int[][] maxDataBitsArray = new int[][]
                {
                    new int[]
                    {
                        0,
                        128,
                        224,
                        352,
                        512,
                        688,
                        864,
                        992,
                        1232,
                        1456,
                        1728,
                        2032,
                        2320,
                        2672,
                        2920,
                        3320,
                        3624,
                        4056,
                        4504,
                        5016,
                        5352,
                        5712,
                        6256,
                        6880,
                        7312,
                        8000,
                        8496,
                        9024,
                        9544,
                        10136,
                        10984,
                        11640,
                        12328,
                        13048,
                        13800,
                        14496,
                        15312,
                        15936,
                        16816,
                        17728,
                        18672
                    },
                    new int[]
                    {
                        0,
                        152,
                        272,
                        440,
                        640,
                        864,
                        1088,
                        1248,
                        1552,
                        1856,
                        2192,
                        2592,
                        2960,
                        3424,
                        3688,
                        4184,
                        4712,
                        5176,
                        5768,
                        6360,
                        6888,
                        7456,
                        8048,
                        8752,
                        9392,
                        10208,
                        10960,
                        11744,
                        12248,
                        13048,
                        13880,
                        14744,
                        15640,
                        16568,
                        17528,
                        18448,
                        19472,
                        20528,
                        21616,
                        22496,
                        23648
                    },
                    new int[]
                    {
                        0,
                        72,
                        128,
                        208,
                        288,
                        368,
                        480,
                        528,
                        688,
                        800,
                        976,
                        1120,
                        1264,
                        1440,
                        1576,
                        1784,
                        2024,
                        2264,
                        2504,
                        2728,
                        3080,
                        3248,
                        3536,
                        3712,
                        4112,
                        4304,
                        4768,
                        5024,
                        5288,
                        5608,
                        5960,
                        6344,
                        6760,
                        7208,
                        7688,
                        7888,
                        8432,
                        8768,
                        9136,
                        9776,
                        10208
                    },
                    new int[]
                    {
                        0,
                        104,
                        176,
                        272,
                        384,
                        496,
                        608,
                        704,
                        880,
                        1056,
                        1232,
                        1440,
                        1648,
                        1952,
                        2088,
                        2360,
                        2600,
                        2936,
                        3176,
                        3560,
                        3880,
                        4096,
                        4544,
                        4912,
                        5312,
                        5744,
                        6032,
                        6464,
                        6968,
                        7288,
                        7880,
                        8264,
                        8920,
                        9368,
                        9848,
                        10288,
                        10832,
                        11408,
                        12016,
                        12656,
                        13328
                    }
                };
                int maxDataBits = 0;
                if (this.qrcodeVersion == 0)
                {
                    this.qrcodeVersion = 1;
                    for (int i = 1; i <= 40; i++)
                    {
                        if (maxDataBitsArray[ec][i] >= totalDataBits + codewordNumPlus[this.qrcodeVersion])
                        {
                            maxDataBits = maxDataBitsArray[ec][i];
                            break;
                        }
                        this.qrcodeVersion++;
                    }
                }
                else
                {
                    maxDataBits = maxDataBitsArray[ec][this.qrcodeVersion];
                }
                totalDataBits += codewordNumPlus[this.qrcodeVersion];
                dataBits[codewordNumCounterValue] = (sbyte)((int)dataBits[codewordNumCounterValue] + codewordNumPlus[this.qrcodeVersion]);
                int[] maxCodewordsArray = new int[]
                {
                    0,
                    26,
                    44,
                    70,
                    100,
                    134,
                    172,
                    196,
                    242,
                    292,
                    346,
                    404,
                    466,
                    532,
                    581,
                    655,
                    733,
                    815,
                    901,
                    991,
                    1085,
                    1156,
                    1258,
                    1364,
                    1474,
                    1588,
                    1706,
                    1828,
                    1921,
                    2051,
                    2185,
                    2323,
                    2465,
                    2611,
                    2761,
                    2876,
                    3034,
                    3196,
                    3362,
                    3532,
                    3706
                };
                int   maxCodewords    = maxCodewordsArray[this.qrcodeVersion];
                int   maxModules1side = 17 + (this.qrcodeVersion << 2);
                int[] matrixRemainBit = new int[]
                {
                    0,
                    0,
                    7,
                    7,
                    7,
                    7,
                    7,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0
                };
                int     byte_num            = matrixRemainBit[this.qrcodeVersion] + (maxCodewords << 3);
                sbyte[] matrixX             = new sbyte[byte_num];
                sbyte[] matrixY             = new sbyte[byte_num];
                sbyte[] maskArray           = new sbyte[byte_num];
                sbyte[] formatInformationX2 = new sbyte[15];
                sbyte[] formatInformationY2 = new sbyte[15];
                sbyte[] rsEccCodewords      = new sbyte[1];
                sbyte[] rsBlockOrderTemp    = new sbyte[128];
                try
                {
                    string         fileName     = "qrv" + Convert.ToString(this.qrcodeVersion) + "_" + Convert.ToString(ec);
                    MemoryStream   memoryStream = new MemoryStream((byte[])Resources.ResourceManager.GetObject(fileName));
                    BufferedStream bis          = new BufferedStream(memoryStream);
                    SystemUtils.ReadInput(bis, matrixX, 0, matrixX.Length);
                    SystemUtils.ReadInput(bis, matrixY, 0, matrixY.Length);
                    SystemUtils.ReadInput(bis, maskArray, 0, maskArray.Length);
                    SystemUtils.ReadInput(bis, formatInformationX2, 0, formatInformationX2.Length);
                    SystemUtils.ReadInput(bis, formatInformationY2, 0, formatInformationY2.Length);
                    SystemUtils.ReadInput(bis, rsEccCodewords, 0, rsEccCodewords.Length);
                    SystemUtils.ReadInput(bis, rsBlockOrderTemp, 0, rsBlockOrderTemp.Length);
                    bis.Close();
                    memoryStream.Close();
                }
                catch (Exception e)
                {
                    SystemUtils.WriteStackTrace(e, Console.Error);
                }
                sbyte rsBlockOrderLength = 1;
                sbyte j = 1;
                while ((int)j < 128)
                {
                    if (rsBlockOrderTemp[(int)j] == 0)
                    {
                        rsBlockOrderLength = j;
                        break;
                    }
                    j += 1;
                }
                sbyte[] rsBlockOrder = new sbyte[(int)rsBlockOrderLength];
                Array.Copy(rsBlockOrderTemp, 0, rsBlockOrder, 0, (int)((byte)rsBlockOrderLength));
                sbyte[] formatInformationX3 = new sbyte[]
                {
                    0,
                    1,
                    2,
                    3,
                    4,
                    5,
                    7,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8
                };
                sbyte[] formatInformationY3 = new sbyte[]
                {
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    7,
                    5,
                    4,
                    3,
                    2,
                    1,
                    0
                };
                int     maxDataCodewords = maxDataBits >> 3;
                int     modules1Side     = 4 * this.qrcodeVersion + 17;
                int     matrixTotalBits  = modules1Side * modules1Side;
                sbyte[] frameData        = new sbyte[matrixTotalBits + modules1Side];
                try
                {
                    string         fileName     = "qrvfr" + Convert.ToString(this.qrcodeVersion);
                    MemoryStream   memoryStream = new MemoryStream((byte[])Resources.ResourceManager.GetObject(fileName));
                    BufferedStream bis          = new BufferedStream(memoryStream);
                    SystemUtils.ReadInput(bis, frameData, 0, frameData.Length);
                    bis.Close();
                    memoryStream.Close();
                }
                catch (Exception e)
                {
                    SystemUtils.WriteStackTrace(e, Console.Error);
                }
                if (totalDataBits <= maxDataBits - 4)
                {
                    dataValue[dataCounter] = 0;
                    dataBits[dataCounter]  = 4;
                }
                else
                {
                    if (totalDataBits < maxDataBits)
                    {
                        dataValue[dataCounter] = 0;
                        dataBits[dataCounter]  = (sbyte)(maxDataBits - totalDataBits);
                    }
                    else
                    {
                        if (totalDataBits > maxDataBits)
                        {
                            Console.Out.WriteLine("overflow");
                        }
                    }
                }
                sbyte[]   dataCodewords = QRCodeEncoder.divideDataBy8Bits(dataValue, dataBits, maxDataCodewords);
                sbyte[]   codewords     = QRCodeEncoder.calculateRSECC(dataCodewords, rsEccCodewords[0], rsBlockOrder, maxDataCodewords, maxCodewords);
                sbyte[][] matrixContent = new sbyte[modules1Side][];
                for (int i2 = 0; i2 < modules1Side; i2++)
                {
                    matrixContent[i2] = new sbyte[modules1Side];
                }
                for (int i = 0; i < modules1Side; i++)
                {
                    for (int k = 0; k < modules1Side; k++)
                    {
                        matrixContent[k][i] = 0;
                    }
                }
                for (int i = 0; i < maxCodewords; i++)
                {
                    sbyte codeword_i = codewords[i];
                    for (int k = 7; k >= 0; k--)
                    {
                        int codewordBitsNumber = i * 8 + k;
                        matrixContent[(int)matrixX[codewordBitsNumber] & 255][(int)matrixY[codewordBitsNumber] & 255] = (sbyte)(255 * (int)(codeword_i & 1) ^ (int)maskArray[codewordBitsNumber]);
                        codeword_i = (sbyte)SystemUtils.URShift((int)codeword_i & 255, 1);
                    }
                }
                for (int matrixRemain = matrixRemainBit[this.qrcodeVersion]; matrixRemain > 0; matrixRemain--)
                {
                    int remainBitTemp = matrixRemain + maxCodewords * 8 - 1;
                    matrixContent[(int)matrixX[remainBitTemp] & 255][(int)matrixY[remainBitTemp] & 255] = (sbyte)(255 ^ (int)maskArray[remainBitTemp]);
                }
                sbyte    maskNumber             = QRCodeEncoder.selectMask(matrixContent, matrixRemainBit[this.qrcodeVersion] + maxCodewords * 8);
                sbyte    maskContent            = (sbyte)(1 << (int)maskNumber);
                sbyte    formatInformationValue = (sbyte)(ec << 3 | (int)maskNumber);
                string[] formatInformationArray = new string[]
                {
                    "101010000010010",
                    "101000100100101",
                    "101111001111100",
                    "101101101001011",
                    "100010111111001",
                    "100000011001110",
                    "100111110010111",
                    "100101010100000",
                    "111011111000100",
                    "111001011110011",
                    "111110110101010",
                    "111100010011101",
                    "110011000101111",
                    "110001100011000",
                    "110110001000001",
                    "110100101110110",
                    "001011010001001",
                    "001001110111110",
                    "001110011100111",
                    "001100111010000",
                    "000011101100010",
                    "000001001010101",
                    "000110100001100",
                    "000100000111011",
                    "011010101011111",
                    "011000001101000",
                    "011111100110001",
                    "011101000000110",
                    "010010010110100",
                    "010000110000011",
                    "010111011011010",
                    "010101111101101"
                };
                for (int i = 0; i < 15; i++)
                {
                    sbyte content = sbyte.Parse(formatInformationArray[(int)formatInformationValue].Substring(i, i + 1 - i));
                    matrixContent[(int)formatInformationX3[i] & 255][(int)formatInformationY3[i] & 255] = (sbyte)((int)content * 255);
                    matrixContent[(int)formatInformationX2[i] & 255][(int)formatInformationY2[i] & 255] = (sbyte)((int)content * 255);
                }
                bool[][] out_Renamed = new bool[modules1Side][];
                for (int i3 = 0; i3 < modules1Side; i3++)
                {
                    out_Renamed[i3] = new bool[modules1Side];
                }
                int c = 0;
                for (int i = 0; i < modules1Side; i++)
                {
                    for (int k = 0; k < modules1Side; k++)
                    {
                        if ((matrixContent[k][i] & maskContent) != 0 || frameData[c] == 49)
                        {
                            out_Renamed[k][i] = true;
                        }
                        else
                        {
                            out_Renamed[k][i] = false;
                        }
                        c++;
                    }
                    c++;
                }
                result = out_Renamed;
            }
            return(result);
        }
Exemple #33
0
        private static sbyte[] calculateRSECC(sbyte[] codewords, sbyte rsEccCodewords, sbyte[] rsBlockOrder, int maxDataCodewords, int maxCodewords)
        {
            sbyte[][] numArray1 = new sbyte[256][];
            for (int index = 0; index < 256; ++index)
            {
                numArray1[index] = new sbyte[(int)rsEccCodewords];
            }
            try
            {
                // ISSUE: reference to a compiler-generated method
                byte[]         qrdata         = ReadData("rsc" + rsEccCodewords.ToString());
                MemoryStream   memoryStream   = new MemoryStream(qrdata);
                BufferedStream bufferedStream = new BufferedStream(memoryStream);
                for (int index = 0; index < 256; ++index)
                {
                    SystemUtils.ReadInput((Stream)bufferedStream, numArray1[index], 0, numArray1[index].Length);
                }
                bufferedStream.Close();
                memoryStream.Close();
            }
            catch (Exception ex)
            {
                SystemUtils.WriteStackTrace(ex, Console.Error);
            }
            int index1 = 0;
            int index2 = 0;

            sbyte[][] numArray2 = new sbyte[rsBlockOrder.Length][];
            sbyte[]   numArray3 = new sbyte[maxCodewords];
            Array.Copy((Array)codewords, 0, (Array)numArray3, 0, codewords.Length);
            for (int index3 = 0; index3 < rsBlockOrder.Length; ++index3)
            {
                numArray2[index3] = new sbyte[((int)rsBlockOrder[index3] & (int)byte.MaxValue) - (int)rsEccCodewords];
            }
            for (int index3 = 0; index3 < maxDataCodewords; ++index3)
            {
                numArray2[index2][index1] = codewords[index3];
                ++index1;
                if (index1 >= ((int)rsBlockOrder[index2] & (int)byte.MaxValue) - (int)rsEccCodewords)
                {
                    index1 = 0;
                    ++index2;
                }
            }
            for (int index3 = 0; index3 < rsBlockOrder.Length; ++index3)
            {
                sbyte[] numArray4 = new sbyte[numArray2[index3].Length];
                numArray2[index3].CopyTo((Array)numArray4, 0);
                for (int index4 = ((int)rsBlockOrder[index3] & (int)byte.MaxValue) - (int)rsEccCodewords; index4 > 0; --index4)
                {
                    sbyte num = numArray4[0];
                    if ((int)num != 0)
                    {
                        sbyte[] xa = new sbyte[numArray4.Length - 1];
                        Array.Copy((Array)numArray4, 1, (Array)xa, 0, numArray4.Length - 1);
                        sbyte[] xb = numArray1[(int)num & (int)byte.MaxValue];
                        numArray4 = QRCodeEncoder.calculateByteArrayBits(xa, xb, "xor");
                    }
                    else if ((int)rsEccCodewords < numArray4.Length)
                    {
                        sbyte[] numArray5 = new sbyte[numArray4.Length - 1];
                        Array.Copy((Array)numArray4, 1, (Array)numArray5, 0, numArray4.Length - 1);
                        numArray4 = new sbyte[numArray5.Length];
                        numArray5.CopyTo((Array)numArray4, 0);
                    }
                    else
                    {
                        sbyte[] numArray5 = new sbyte[(int)rsEccCodewords];
                        Array.Copy((Array)numArray4, 1, (Array)numArray5, 0, numArray4.Length - 1);
                        numArray5[(int)rsEccCodewords - 1] = (sbyte)0;
                        numArray4 = new sbyte[numArray5.Length];
                        numArray5.CopyTo((Array)numArray4, 0);
                    }
                }
                Array.Copy((Array)numArray4, 0, (Array)numArray3, codewords.Length + index3 * (int)rsEccCodewords, (int)(byte)rsEccCodewords);
            }
            return(numArray3);
        }
Exemple #34
0
        public virtual bool[][] calQrcode(byte[] qrcodeData)
        {
            int index1  = 0;
            int length1 = qrcodeData.Length;

            int[]   data = new int[length1 + 32];
            sbyte[] bits = new sbyte[length1 + 32];
            if (length1 <= 0)
            {
                return new bool[1][] { new bool[1] }
            }
            ;
            if (this.qrcodeStructureappendN > 1)
            {
                data[0] = 3;

                bits[0] = (sbyte)4;
                data[1] = this.qrcodeStructureappendM - 1;
                bits[1] = (sbyte)4;
                data[2] = this.qrcodeStructureappendN - 1;
                bits[2] = (sbyte)4;
                data[3] = this.qrcodeStructureappendParity;
                bits[3] = (sbyte)8;
                index1  = 4;
            }
            bits[index1] = (sbyte)4;
            int[] numArray1;
            int   index2;
            int   index3;

            switch (this.qrcodeEncodeMode)
            {
            case QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC:
                numArray1 = new int[41]
                {
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4
                };
                data[index1] = 2;
                int index4 = index1 + 1;
                data[index4] = length1;
                bits[index4] = (sbyte)9;
                index2       = index4;
                int index5 = index4 + 1;
                for (int index6 = 0; index6 < length1; ++index6)
                {
                    char  ch  = (char)qrcodeData[index6];
                    sbyte num = 0;
                    if ((int)ch >= 48 && (int)ch < 58)
                    {
                        num = (sbyte)((int)ch - 48);
                    }
                    else if ((int)ch >= 65 && (int)ch < 91)
                    {
                        num = (sbyte)((int)ch - 55);
                    }
                    else
                    {
                        if ((int)ch == 32)
                        {
                            num = (sbyte)36;
                        }
                        if ((int)ch == 36)
                        {
                            num = (sbyte)37;
                        }
                        if ((int)ch == 37)
                        {
                            num = (sbyte)38;
                        }
                        if ((int)ch == 42)
                        {
                            num = (sbyte)39;
                        }
                        if ((int)ch == 43)
                        {
                            num = (sbyte)40;
                        }
                        if ((int)ch == 45)
                        {
                            num = (sbyte)41;
                        }
                        if ((int)ch == 46)
                        {
                            num = (sbyte)42;
                        }
                        if ((int)ch == 47)
                        {
                            num = (sbyte)43;
                        }
                        if ((int)ch == 58)
                        {
                            num = (sbyte)44;
                        }
                    }
                    if (index6 % 2 == 0)
                    {
                        data[index5] = (int)num;
                        bits[index5] = (sbyte)6;
                    }
                    else
                    {
                        data[index5] = data[index5] * 45 + (int)num;
                        bits[index5] = (sbyte)11;
                        if (index6 < length1 - 1)
                        {
                            ++index5;
                        }
                    }
                }
                index3 = index5 + 1;
                break;

            case QRCodeEncoder.ENCODE_MODE.NUMERIC:
                numArray1 = new int[41]
                {
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4
                };
                data[index1] = 1;
                int index7 = index1 + 1;
                data[index7] = length1;
                bits[index7] = (sbyte)10;
                index2       = index7;
                int index8 = index7 + 1;
                for (int index6 = 0; index6 < length1; ++index6)
                {
                    if (index6 % 3 == 0)
                    {
                        data[index8] = (int)qrcodeData[index6] - 48;
                        bits[index8] = (sbyte)4;
                    }
                    else
                    {
                        data[index8] = data[index8] * 10 + ((int)qrcodeData[index6] - 48);
                        if (index6 % 3 == 1)
                        {
                            bits[index8] = (sbyte)7;
                        }
                        else
                        {
                            bits[index8] = (sbyte)10;
                            if (index6 < length1 - 1)
                            {
                                ++index8;
                            }
                        }
                    }
                }
                index3 = index8 + 1;
                break;

            default:
                numArray1 = new int[41]
                {
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8
                };
                data[index1] = 4;
                int index9 = index1 + 1;
                data[index9] = length1;
                bits[index9] = (sbyte)8;
                index2       = index9;
                int num1 = index9 + 1;
                for (int index6 = 0; index6 < length1; ++index6)
                {
                    data[index6 + num1] = (int)qrcodeData[index6] & (int)byte.MaxValue;
                    bits[index6 + num1] = (sbyte)8;
                }
                index3 = num1 + length1;
                break;
            }
            int num2 = 0;

            for (int index6 = 0; index6 < index3; ++index6)
            {
                num2 += (int)bits[index6];
            }
            int index10;

            switch (this.qrcodeErrorCorrect)
            {
            case QRCodeEncoder.ERROR_CORRECTION.L:
                index10 = 1;
                break;

            case QRCodeEncoder.ERROR_CORRECTION.Q:
                index10 = 3;
                break;

            case QRCodeEncoder.ERROR_CORRECTION.H:
                index10 = 2;
                break;

            default:
                index10 = 0;
                break;
            }
            int[][] numArray2 = new int[4][]
            {
                new int[41]
                {
                    0,
                    128,
                    224,
                    352,
                    512,
                    688,
                    864,
                    992,
                    1232,
                    1456,
                    1728,
                    2032,
                    2320,
                    2672,
                    2920,
                    3320,
                    3624,
                    4056,
                    4504,
                    5016,
                    5352,
                    5712,
                    6256,
                    6880,
                    7312,
                    8000,
                    8496,
                    9024,
                    9544,
                    10136,
                    10984,
                    11640,
                    12328,
                    13048,
                    13800,
                    14496,
                    15312,
                    15936,
                    16816,
                    17728,
                    18672
                },
                new int[41]
                {
                    0,
                    152,
                    272,
                    440,
                    640,
                    864,
                    1088,
                    1248,
                    1552,
                    1856,
                    2192,
                    2592,
                    2960,
                    3424,
                    3688,
                    4184,
                    4712,
                    5176,
                    5768,
                    6360,
                    6888,
                    7456,
                    8048,
                    8752,
                    9392,
                    10208,
                    10960,
                    11744,
                    12248,
                    13048,
                    13880,
                    14744,
                    15640,
                    16568,
                    17528,
                    18448,
                    19472,
                    20528,
                    21616,
                    22496,
                    23648
                },
                new int[41]
                {
                    0,
                    72,
                    128,
                    208,
                    288,
                    368,
                    480,
                    528,
                    688,
                    800,
                    976,
                    1120,
                    1264,
                    1440,
                    1576,
                    1784,
                    2024,
                    2264,
                    2504,
                    2728,
                    3080,
                    3248,
                    3536,
                    3712,
                    4112,
                    4304,
                    4768,
                    5024,
                    5288,
                    5608,
                    5960,
                    6344,
                    6760,
                    7208,
                    7688,
                    7888,
                    8432,
                    8768,
                    9136,
                    9776,
                    10208
                },
                new int[41]
                {
                    0,
                    104,
                    176,
                    272,
                    384,
                    496,
                    608,
                    704,
                    880,
                    1056,
                    1232,
                    1440,
                    1648,
                    1952,
                    2088,
                    2360,
                    2600,
                    2936,
                    3176,
                    3560,
                    3880,
                    4096,
                    4544,
                    4912,
                    5312,
                    5744,
                    6032,
                    6464,
                    6968,
                    7288,
                    7880,
                    8264,
                    8920,
                    9368,
                    9848,
                    10288,
                    10832,
                    11408,
                    12016,
                    12656,
                    13328
                }
            };
            int num3 = 0;

            if (this.qrcodeVersion == 0)
            {
                this.qrcodeVersion = 1;
                for (int index6 = 1; index6 <= 40; ++index6)
                {
                    if (numArray2[index10][index6] >= num2 + numArray1[this.qrcodeVersion])
                    {
                        num3 = numArray2[index10][index6];
                        break;
                    }
                    ++this.qrcodeVersion;
                }
            }
            else
            {
                num3 = numArray2[index10][this.qrcodeVersion];
            }
            int num4 = num2 + numArray1[this.qrcodeVersion];

            bits[index2] = (sbyte)((int)bits[index2] + numArray1[this.qrcodeVersion]);
            int maxCodewords = new int[41]
            {
                0,
                26,
                44,
                70,
                100,
                134,
                172,
                196,
                242,
                292,
                346,
                404,
                466,
                532,
                581,
                655,
                733,
                815,
                901,
                991,
                1085,
                1156,
                1258,
                1364,
                1474,
                1588,
                1706,
                1828,
                1921,
                2051,
                2185,
                2323,
                2465,
                2611,
                2761,
                2876,
                3034,
                3196,
                3362,
                3532,
                3706
            }[this.qrcodeVersion];
            int num5 = 17 + (this.qrcodeVersion << 2);

            int[] numArray3 = new int[41]
            {
                0,
                0,
                7,
                7,
                7,
                7,
                7,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                3,
                3,
                3,
                3,
                3,
                3,
                3,
                4,
                4,
                4,
                4,
                4,
                4,
                4,
                3,
                3,
                3,
                3,
                3,
                3,
                3,
                0,
                0,
                0,
                0,
                0,
                0
            };
            int length2 = numArray3[this.qrcodeVersion] + (maxCodewords << 3);

            sbyte[] target1 = new sbyte[length2];
            sbyte[] target2 = new sbyte[length2];
            sbyte[] target3 = new sbyte[length2];
            sbyte[] target4 = new sbyte[15];
            sbyte[] target5 = new sbyte[15];
            sbyte[] target6 = new sbyte[1];
            sbyte[] target7 = new sbyte[128];
            try
            {
                // ISSUE: reference to a compiler-generated method
                var            resKey         = "qrv" + Convert.ToString(qrcodeVersion) + "_" + Convert.ToString(index10);
                byte[]         qrdata         = ReadData(resKey);
                MemoryStream   memoryStream   = new MemoryStream(qrdata);
                BufferedStream bufferedStream = new BufferedStream(memoryStream);
                SystemUtils.ReadInput((Stream)bufferedStream, target1, 0, target1.Length);
                SystemUtils.ReadInput((Stream)bufferedStream, target2, 0, target2.Length);
                SystemUtils.ReadInput((Stream)bufferedStream, target3, 0, target3.Length);
                SystemUtils.ReadInput((Stream)bufferedStream, target4, 0, target4.Length);
                SystemUtils.ReadInput((Stream)bufferedStream, target5, 0, target5.Length);
                SystemUtils.ReadInput((Stream)bufferedStream, target6, 0, target6.Length);
                SystemUtils.ReadInput((Stream)bufferedStream, target7, 0, target7.Length);
                bufferedStream.Close();
                memoryStream.Close();
            }
            catch (Exception ex)
            {
                SystemUtils.WriteStackTrace(ex, Console.Error);
            }
            sbyte num6 = 1;

            for (sbyte index6 = 1; (int)index6 < 128; ++index6)
            {
                if ((int)target7[(int)index6] == 0)
                {
                    num6 = index6;
                    break;
                }
            }
            sbyte[] rsBlockOrder = new sbyte[(int)num6];
            Array.Copy((Array)target7, 0, (Array)rsBlockOrder, 0, (int)(byte)num6);
            sbyte[] numArray4 = new sbyte[15]
            {
                (sbyte)0,
                (sbyte)1,
                (sbyte)2,
                (sbyte)3,
                (sbyte)4,
                (sbyte)5,
                (sbyte)7,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8
            };
            sbyte[] numArray5 = new sbyte[15]
            {
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)7,
                (sbyte)5,
                (sbyte)4,
                (sbyte)3,
                (sbyte)2,
                (sbyte)1,
                (sbyte)0
            };
            int maxDataCodewords = num3 >> 3;
            int length3          = 4 * this.qrcodeVersion + 17;

            sbyte[] target8 = new sbyte[length3 * length3 + length3];
            try
            {
                // ISSUE: reference to a compiler-generated method
                byte[]         qrdata         = ReadData("qrvfr" + Convert.ToString(this.qrcodeVersion));
                MemoryStream   memoryStream   = new MemoryStream(qrdata);
                BufferedStream bufferedStream = new BufferedStream((Stream)memoryStream);
                SystemUtils.ReadInput((Stream)bufferedStream, target8, 0, target8.Length);
                bufferedStream.Close();
                memoryStream.Close();
            }
            catch (Exception ex)
            {
                SystemUtils.WriteStackTrace(ex, Console.Error);
            }
            if (num4 <= num3 - 4)
            {
                data[index3] = 0;
                bits[index3] = (sbyte)4;
            }
            else if (num4 < num3)
            {
                data[index3] = 0;
                bits[index3] = (sbyte)(num3 - num4);
            }
            else if (num4 > num3)
            {
                Console.Out.WriteLine("overflow");
            }
            sbyte[]   rsecc         = QRCodeEncoder.calculateRSECC(QRCodeEncoder.divideDataBy8Bits(data, bits, maxDataCodewords), target6[0], rsBlockOrder, maxDataCodewords, maxCodewords);
            sbyte[][] matrixContent = new sbyte[length3][];
            for (int index6 = 0; index6 < length3; ++index6)
            {
                matrixContent[index6] = new sbyte[length3];
            }
            for (int index6 = 0; index6 < length3; ++index6)
            {
                for (int index11 = 0; index11 < length3; ++index11)
                {
                    matrixContent[index11][index6] = (sbyte)0;
                }
            }
            for (int index6 = 0; index6 < maxCodewords; ++index6)
            {
                sbyte num7 = rsecc[index6];
                for (int index11 = 7; index11 >= 0; --index11)
                {
                    int index12 = index6 * 8 + index11;
                    matrixContent[(int)target1[index12] & (int)byte.MaxValue][(int)target2[index12] & (int)byte.MaxValue] = (sbyte)((int)byte.MaxValue * ((int)num7 & 1) ^ (int)target3[index12]);
                    num7 = (sbyte)SystemUtils.URShift((int)num7 & (int)byte.MaxValue, 1);
                }
            }
            for (int index6 = numArray3[this.qrcodeVersion]; index6 > 0; --index6)
            {
                int index11 = index6 + maxCodewords * 8 - 1;
                matrixContent[(int)target1[index11] & (int)byte.MaxValue][(int)target2[index11] & (int)byte.MaxValue] = (sbyte)((int)byte.MaxValue ^ (int)target3[index11]);
            }
            sbyte num8  = QRCodeEncoder.selectMask(matrixContent, numArray3[this.qrcodeVersion] + maxCodewords * 8);
            sbyte num9  = (sbyte)(1 << (int)num8);
            sbyte num10 = (sbyte)(index10 << 3 | (int)num8);

            string[] strArray = new string[32]
            {
                "101010000010010",
                "101000100100101",
                "101111001111100",
                "101101101001011",
                "100010111111001",
                "100000011001110",
                "100111110010111",
                "100101010100000",
                "111011111000100",
                "111001011110011",
                "111110110101010",
                "111100010011101",
                "110011000101111",
                "110001100011000",
                "110110001000001",
                "110100101110110",
                "001011010001001",
                "001001110111110",
                "001110011100111",
                "001100111010000",
                "000011101100010",
                "000001001010101",
                "000110100001100",
                "000100000111011",
                "011010101011111",
                "011000001101000",
                "011111100110001",
                "011101000000110",
                "010010010110100",
                "010000110000011",
                "010111011011010",
                "010101111101101"
            };
            for (int startIndex = 0; startIndex < 15; ++startIndex)
            {
                sbyte num7 = sbyte.Parse(strArray[(int)num10].Substring(startIndex, startIndex + 1 - startIndex));
                matrixContent[(int)numArray4[startIndex] & (int)byte.MaxValue][(int)numArray5[startIndex] & (int)byte.MaxValue] = (sbyte)((int)num7 * (int)byte.MaxValue);
                matrixContent[(int)target4[startIndex] & (int)byte.MaxValue][(int)target5[startIndex] & (int)byte.MaxValue]     = (sbyte)((int)num7 * (int)byte.MaxValue);
            }
            bool[][] flagArray = new bool[length3][];
            for (int index6 = 0; index6 < length3; ++index6)
            {
                flagArray[index6] = new bool[length3];
            }
            int index13 = 0;

            for (int index6 = 0; index6 < length3; ++index6)
            {
                for (int index11 = 0; index11 < length3; ++index11)
                {
                    int num7 = ((int)matrixContent[index11][index6] & (int)num9) != 0 ? 0 : ((int)target8[index13] != 49 ? 1 : 0);
                    flagArray[index11][index6] = num7 == 0;
                    ++index13;
                }
                ++index13;
            }
            return(flagArray);
        }
Exemple #35
0
        private static sbyte[] calculateRSECC(sbyte[] codewords, sbyte rsEccCodewords, sbyte[] rsBlockOrder, int maxDataCodewords, int maxCodewords)
        {
            sbyte[][] rsCalTableArray = new sbyte[256][];
            for (int i = 0; i < 256; i++)
            {
                rsCalTableArray[i] = new sbyte[(int)rsEccCodewords];
            }
            try
            {
                string         fileName     = "rsc" + rsEccCodewords.ToString();
                MemoryStream   memoryStream = new MemoryStream((byte[])Resources.ResourceManager.GetObject(fileName));
                BufferedStream bis          = new BufferedStream(memoryStream);
                for (int i = 0; i < 256; i++)
                {
                    SystemUtils.ReadInput(bis, rsCalTableArray[i], 0, rsCalTableArray[i].Length);
                }
                bis.Close();
                memoryStream.Close();
            }
            catch (Exception e)
            {
                SystemUtils.WriteStackTrace(e, Console.Error);
            }
            int j             = 0;
            int rsBlockNumber = 0;

            sbyte[][] rsTemp = new sbyte[rsBlockOrder.Length][];
            sbyte[]   res    = new sbyte[maxCodewords];
            Array.Copy(codewords, 0, res, 0, codewords.Length);
            for (int i2 = 0; i2 < rsBlockOrder.Length; i2++)
            {
                rsTemp[i2] = new sbyte[((int)rsBlockOrder[i2] & 255) - (int)rsEccCodewords];
            }
            for (int i2 = 0; i2 < maxDataCodewords; i2++)
            {
                rsTemp[rsBlockNumber][j] = codewords[i2];
                j++;
                if (j >= ((int)rsBlockOrder[rsBlockNumber] & 255) - (int)rsEccCodewords)
                {
                    j = 0;
                    rsBlockNumber++;
                }
            }
            for (rsBlockNumber = 0; rsBlockNumber < rsBlockOrder.Length; rsBlockNumber++)
            {
                sbyte[] rsTempData = new sbyte[rsTemp[rsBlockNumber].Length];
                rsTemp[rsBlockNumber].CopyTo(rsTempData, 0);
                int rsCodewords     = (int)rsBlockOrder[rsBlockNumber] & 255;
                int rsDataCodewords = rsCodewords - (int)rsEccCodewords;
                for (j = rsDataCodewords; j > 0; j--)
                {
                    sbyte first = rsTempData[0];
                    if (first != 0)
                    {
                        sbyte[] leftChr = new sbyte[rsTempData.Length - 1];
                        Array.Copy(rsTempData, 1, leftChr, 0, rsTempData.Length - 1);
                        sbyte[] cal = rsCalTableArray[(int)first & 255];
                        rsTempData = QRCodeEncoder.calculateByteArrayBits(leftChr, cal, "xor");
                    }
                    else
                    {
                        if ((int)rsEccCodewords < rsTempData.Length)
                        {
                            sbyte[] rsTempNew = new sbyte[rsTempData.Length - 1];
                            Array.Copy(rsTempData, 1, rsTempNew, 0, rsTempData.Length - 1);
                            rsTempData = new sbyte[rsTempNew.Length];
                            rsTempNew.CopyTo(rsTempData, 0);
                        }
                        else
                        {
                            sbyte[] rsTempNew = new sbyte[(int)rsEccCodewords];
                            Array.Copy(rsTempData, 1, rsTempNew, 0, rsTempData.Length - 1);
                            rsTempNew[(int)(rsEccCodewords - 1)] = 0;
                            rsTempData = new sbyte[rsTempNew.Length];
                            rsTempNew.CopyTo(rsTempData, 0);
                        }
                    }
                }
                Array.Copy(rsTempData, 0, res, codewords.Length + rsBlockNumber * (int)rsEccCodewords, (int)((byte)rsEccCodewords));
            }
            return(res);
        }
Exemple #36
-1
 public void CreateQRCode(string userName)
 {
     Bitmap bt;
     string enCodeString = userName;
     QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
     bt = qrCodeEncoder.Encode(enCodeString, Encoding.UTF8);
     //string filename = string.Format(DateTime.Now.ToString(), "yyyymmddhhmmss");
     //filename = filename.Replace(" ", "");
     //filename = filename.Replace(":", "");
     //filename = filename.Replace("-", "");
     //filename = filename.Replace(".", "");
     //filename = filename + userName;
     bt.Save(System.Web.HttpContext.Current.Server.MapPath("~/QRCode/") + userName + ".bmp");
     //this.Image1.ImageUrl = "~/Images/" + filename + ".jpg";
 }