Пример #1
0
        private void GenQR(string ssconfig)
        {
            string qrText = ssconfig;

            QRCode4CS.Options options = new QRCode4CS.Options();
            options.Text = qrText;
            QRCode4CS.QRCode qrCoded = null;
            bool             success = false;

            foreach (var level in new QRErrorCorrectLevel[] { QRErrorCorrectLevel.H, QRErrorCorrectLevel.Q, QRErrorCorrectLevel.M, QRErrorCorrectLevel.L })
            {
                for (int i = 3; i < 10; i++)
                {
                    try
                    {
                        options.TypeNumber   = i;
                        options.CorrectLevel = level;
                        qrCoded = new QRCode4CS.QRCode(options);
                        qrCoded.Make();
                        success = true;
                        break;
                    }
                    catch
                    {
                        qrCoded = null;
                        continue;
                    }
                }
                if (success)
                {
                    break;
                }
            }
            if (qrCoded == null)
            {
                return;
            }
            int    blockSize = Math.Max(200 / qrCoded.GetModuleCount(), 1);
            Bitmap drawArea  = new Bitmap((qrCoded.GetModuleCount() * blockSize), (qrCoded.GetModuleCount() * blockSize));

            using (Graphics g = Graphics.FromImage(drawArea))
            {
                g.Clear(Color.White);
                using (Brush b = new SolidBrush(Color.Black))
                {
                    for (int row = 0; row < qrCoded.GetModuleCount(); row++)
                    {
                        for (int col = 0; col < qrCoded.GetModuleCount(); col++)
                        {
                            if (qrCoded.IsDark(row, col))
                            {
                                g.FillRectangle(b, blockSize * row, blockSize * col, blockSize, blockSize);
                            }
                        }
                    }
                }
            }
            pictureBox1.Image = drawArea;
        }
Пример #2
0
 private void GenQR(string ssconfig)
 {
     string qrText = ssconfig;
     QRCode4CS.Options options = new QRCode4CS.Options();
     options.Text = qrText;
     QRCode4CS.QRCode qrCoded = null;
     bool success = false;
     foreach (var level in new QRErrorCorrectLevel[]{QRErrorCorrectLevel.H, QRErrorCorrectLevel.Q, QRErrorCorrectLevel.M, QRErrorCorrectLevel.L})
     {
         for (int i = 3; i < 10; i++)
         {
             try
             {
                 options.TypeNumber = i;
                 options.CorrectLevel = level;
                 qrCoded = new QRCode4CS.QRCode(options);
                 qrCoded.Make();
                 success = true;
                 break;
             }
             catch
             {
                 qrCoded = null;
                 continue;
             }
         }
         if (success)
             break;
     }
     if (qrCoded == null)
     {
         return;
     }
     int blockSize = Math.Max(200 / qrCoded.GetModuleCount(), 1);
     Bitmap drawArea = new Bitmap((qrCoded.GetModuleCount() * blockSize), (qrCoded.GetModuleCount() * blockSize));
     using (Graphics g = Graphics.FromImage(drawArea))
     {
         g.Clear(Color.White);
         using (Brush b = new SolidBrush(Color.Black))
         {
             for (int row = 0; row < qrCoded.GetModuleCount(); row++)
             {
                 for (int col = 0; col < qrCoded.GetModuleCount(); col++)
                 {
                     if (qrCoded.IsDark(row, col))
                     {
                         g.FillRectangle(b, blockSize * row, blockSize * col, blockSize, blockSize);
                     }
                 }
             }
         }
     }
     pictureBox1.Image = drawArea;
 }
Пример #3
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            FOutput.SliceCount = SpreadMax;
            FSize.SliceCount   = SpreadMax;
            FError.SliceCount  = SpreadMax;

            for (int i = 0; i < SpreadMax; i++)
            {
                if (FGen[i])
                {
                    FError[i] = "";
                    try
                    {
                        QRCode4CS.Options options = new QRCode4CS.Options(FInput[i]);
                        options.TypeNumber   = FTypeN[i];
                        options.CorrectLevel = FErrorC[i];
                        QRCode qrcode = new QRCode(options);
                        qrcode.Make();
                        int mcount = qrcode.GetModuleCount();
                        FOutput[i].SliceCount = mcount * mcount;

                        for (int row = 0; row < mcount; row++)
                        {
                            for (int col = 0; col < mcount; col++)
                            {
                                bool isDark = qrcode.IsDark(row, col);
                                FOutput[i][row * mcount + col] = isDark;
                            }
                        }
                        FSize[i] = mcount;
                    }
                    catch (Exception e)
                    {
                        FSize[i] = 0;
                        FOutput[i].SliceCount = 0;
                        FError[i]             = e.Message;
                    }
                }
            }

            //FLogger.Log(LogType.Debug, "hi TTY");
        }