예제 #1
0
파일: Form1.cs 프로젝트: hdf/QRSnap
        private void Scan()
        {
            if (ClientSize.Width == 0 || QRCodeDecoder == null)
            {
                return;
            }
            if (QRCodeInputImage != null)
            {
                QRCodeInputImage.Dispose();
            }
            int w = this.ClientRectangle.Width;
            int h = this.ClientRectangle.Height;
            int l = this.Left + (this.Width - w) / 2;
            int t = this.Top + (this.Height - h - l + this.Left);

            //this.Opacity = 0;
            textBox1.Text      = "";
            textBox1.BackColor = System.Drawing.Color.Gray;
            QRCodeInputImage   = new Bitmap(w, h);
            using (Graphics g = Graphics.FromImage(QRCodeInputImage))
                g.CopyFromScreen(l, t, 0, 0, QRCodeInputImage.Size, CopyPixelOperation.SourceCopy);
            //pictureBox1.Image = QRCodeInputImage;
            byte[][] DataByteArray = QRCodeDecoder.ImageDecoder(QRCodeInputImage);
            textBox1.Text = QRDecoder.QRCodeResult(DataByteArray);
            if (textBox1.Text != "")
            {
                textBox1.BackColor = System.Drawing.Color.White;
                System.Windows.Forms.Clipboard.SetText(textBox1.Text);
            }
            //this.Opacity = 100;
        }
예제 #2
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);

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

            // enable buttons
            LoadImageButton.Enabled = true;

            // force repaint
            Invalidate();
            return;
        }