Exemplo n.º 1
0
        public void UpdateQrCode()
        {
            string         tempString   = tempInvalidQrWorkAround();
            QrEncodeHelper qrAssistance = new QrEncodeHelper(tempString);

            int errorCorrectionLevel;

            versionNum = qrAssistance.DetermineBestVersionAndErrorCorrection(encodingType, DetermineErrorCorrection(), out errorCorrectionLevel);

            bool[,] dataArray;

            //17 is the base + 2 for the border plus 4 times the version number as the square increases by 4 for each version increase
            squareSize = 17 + 2 + 4 * versionNum;

            QrEncode newQr = new QrEncode(versionNum, errorCorrectionLevel);

            myCanvas = new Bitmap(squareSize * pixelDensity, squareSize * pixelDensity);
            Graphics g = Graphics.FromImage(myCanvas);

            g.Clear(Color.White);

            dataArray = newQr.EncodeTheData(tempString);

            //draws all of the pixels that are to be filled in
            for (int x = 0; x < dataArray.GetLength(0); x++)
            {
                for (int y = 0; y < dataArray.GetLength(0); y++)
                {
                    if (dataArray[x, y] == true)
                    {
                        SetPixel(x, y, true);
                    }
                }
            }

            //LABELS ARE NICE - also provides IMPORTANT data to me as i use it
            messageLengthLBL.Text = "Message Length: " + qrStringIn.Text.Length;
            versionLBL.Text       = "Version: " + versionNum;
            maskLBL.Text          = "Mask: " + newQr.mask;

            //appropriate error correction tag is set in the form
            switch (errorCorrectionLevel)
            {
            case 2:
                bchLVL.Text = "EC: H";
                break;

            case 3:
                bchLVL.Text = "EC: Q";
                break;

            case 0:
                bchLVL.Text = "EC: M";
                break;

            case 1:
                bchLVL.Text = "EC: L";
                break;
            }
            if (System.IO.File.Exists(System.Environment.CurrentDirectory.ToString() + "\\magic.png"))
            {
                mainPicBox.Load(System.Environment.CurrentDirectory.ToString() + "\\magic2.png");
                System.IO.File.Delete(System.Environment.CurrentDirectory.ToString() + "\\magic.png");
            }
            myCanvas.Save(System.Environment.CurrentDirectory.ToString() + "\\magic.png", System.Drawing.Imaging.ImageFormat.Png);
            mainPicBox.Load(System.Environment.CurrentDirectory.ToString() + "\\magic.png");
        }