예제 #1
0
        private void OnLoadImage(object sender, EventArgs e)
        {
            // get file name to decode
            OpenFileDialog Dialog = new OpenFileDialog
            {
                Filter           = "Image Files(*.png;*.jpg;*.gif;*.tif)|*.png;*.jpg;*.gif;*.tif;*.bmp)|All files (*.*)|*.*",
                Title            = "Load QR Code Image",
                InitialDirectory = Directory.GetCurrentDirectory(),
                RestoreDirectory = true,
                FileName         = string.Empty
            };

            // display dialog box
            if (Dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // clear parameters
            ImageFileLabel.Text = Dialog.FileName;

            // disable buttons
            LoadImageButton.Enabled = false;

            // dispose previous image
            if (QRCodeInputImage != null)
            {
                QRCodeInputImage.Dispose();
            }

            // load image to bitmap
            QRCodeInputImage = new Bitmap(Dialog.FileName);

            // trace
                #if DEBUG
            QRCodeTrace.Format("****");
            QRCodeTrace.Format("Decode image: {0} ", Dialog.FileName);
            QRCodeTrace.Format("Image width: {0}, Height: {1}", QRCodeInputImage.Width, QRCodeInputImage.Height);
                #endif

            // decode image
            byte[][] DataByteArray = QRCodeDecoder.ImageDecoder(QRCodeInputImage);

            // display ECI value
            ECIValueLabel.Text = QRCodeDecoder.ECIAssignValue >= 0 ? QRCodeDecoder.ECIAssignValue.ToString() : null;

            // convert results to text
            DataTextBox.Text = QRCodeResult(DataByteArray);

            // enable buttons
            LoadImageButton.Enabled = true;

            // force repaint
            Invalidate();
            return;
        }
        private void QRCodeTimer_Tick(object sender, EventArgs e)
        {
            QRCodeTimer.Enabled = false;
            Bitmap QRCodeImage;

            try
            {
                QRCodeImage = VideoCamera.SnapshotSourceImage();

                // trace
                        #if DEBUG
                QRCodeTrace.Format("Image width: {0}, Height: {1}", QRCodeImage.Width, QRCodeImage.Height);
                        #endif
            }

            catch (Exception EX)
            {
                DataTextBox.Text    = "Decode exception.\r\n" + EX.Message;
                QRCodeTimer.Enabled = true;
                return;
            }

            // decode image
            byte[][] DataByteArray = Decoder.ImageDecoder(QRCodeImage);
            string   Text          = QRCodeResult(DataByteArray);

            // dispose bitmap
            QRCodeImage.Dispose();

            // we have no QR code
            if (Text.Length == 0)
            {
                QRCodeTimer.Enabled = true;
                return;
            }

            VideoCamera.PauseGraph();

            DataTextBox.Text    = Text;
            ResetButton.Enabled = true;
            if (IsValidUri(DataTextBox.Text))
            {
                GoToUriButton.Enabled = true;
            }
            return;
        }