Beispiel #1
1
 public static string GetCodeFromPicture(Bitmap pic)
 {
     QRCodeDecoder decoder = new QRCodeDecoder();
     MessagingToolkit.QRCode.Codec.Data.QRCodeBitmapImage image = new QRCodeBitmapImage(pic);
     return decoder.Decode(image, Encoding.Unicode);
 }
Beispiel #2
0
 private void decode_Qr()
 {
     QRCodeBitmapImage qbm = new QRCodeBitmapImage(de_bmp);
     QRCodeDecoder decodeer = new QRCodeDecoder();
       textBox1.Text= decodeer.Decode(qbm);
 }
Beispiel #3
0
        /// <summary>
        /// Click on the camera. Opens a QRCode for prefiled code.
        /// </summary>
        /// <param name="sender">Button.</param>
        /// <param name="e">Nothing.</param>
        void Btn_imageClick(object sender, EventArgs e)
        {
            if (ofd_picture.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    QRCodeDecoder decoder = new QRCodeDecoder();
                    QRCodeImage img = new QRCodeBitmapImage((Bitmap)Bitmap.FromFile(ofd_picture.FileName));
                    string data = decoder.Decode(img);

                    Uri u = new Uri(data);

                    if (u.Scheme != "otpauth" || u.Host != "totp")
                    {
                        throw new Exception();
                    }

                    if (u.AbsolutePath.Length > 1)
                    {
                        txt_name.Text = System.Uri.UnescapeDataString(u.AbsolutePath.Substring(1));
                    }
                    if (u.Query.Length > 8)
                    {
                        txt_code.Text = u.Query.Substring(8);
                    }
                }
                catch
                {
                    MessageBox.Show("Error loading image",
                                    "Error while loading image. Is it a QRCode with totp data ?",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }
        }