상속: MonoBehaviour
예제 #1
0
        public MainWindow()
        {
            InitializeComponent();
            try
            {
                Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
                ofd.ShowDialog();

                System.Drawing.Bitmap bi = new System.Drawing.Bitmap(ofd.FileName);
                //System.Drawing.Bitmap bi =  Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
                Decoder = new QRDecoder();

                // call image decoder methos with <code>Bitmap</code> image of QRCode barcode
                byte[][] DataByteArray = Decoder.ImageDecoder(bi);
                // convert binary result to text string

                MessageBox.Show(DataByteArray.GetLength(0).ToString());// + "\n" + DataByteArray.GetLength(1).ToString());
                string Result = ByteArrayToStr(DataByteArray[0]);

                // string Result = ByteArrayToStr(DataByteArray[Index]);


                MessageBox.Show(Result);
                Clipboard.SetText(Result);
                QRoutput.Content = (Result);
                webbrowser.Navigate(Result);
            }
            catch (Exception ex)
            {
                MessageBox.Show("This QR code is incorrect or incomplete\n" + ex.Message);
            }
        }
예제 #2
0
        public static string getQRCode(string path)
        {
            try
            {
                // create QR Code decoder object
                QRDecoder Decoder = new QRDecoder();
                Bitmap    image   = (Bitmap)Image.FromFile(path, true);

                // call image decoder methos with <code>Bitmap</code> image of QRCode barcode
                byte[][] DataByteArray = Decoder.ImageDecoder(image);

                // get the ECI Assignment value
                //var ECIValue = Decoder.ECIAssignValue;
                //ECIValue = Decoder.ECIAssignValue;
                //if (ECIValue == -1)
                //{
                //    // Assignment value not defined
                //}
                //else
                //{
                //    // Assignment value between 0 to 999999
                //}
                string Result = ByteArrayToStr(DataByteArray[0]);
                return(Result);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #3
0
파일: Form1.cs 프로젝트: hdf/QRSnap
 private void Form1_Load(object sender, EventArgs e)
 {
     QRCodeDecoder        = new QRDecoder();
     this.BackColor       = System.Drawing.Color.Gray;
     this.TransparencyKey = System.Drawing.Color.Gray;
     Scan();
 }
        /// <summary>
        /// Test decode program initialization
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event arguments</param>
        private void OnLoad(object sender, EventArgs e)
        {
            // program title
            Text = "QRCodeDecoderDemo - " + QRDecoder.VersionNumber + " \u00a9 2013-2018 Uzi Granot. All rights reserved.";

                #if DEBUG
            // current directory
            string CurDir  = Environment.CurrentDirectory;
            string WorkDir = CurDir.Replace("bin\\Debug", "Work");
            if (WorkDir != CurDir && Directory.Exists(WorkDir))
            {
                Environment.CurrentDirectory = WorkDir;
            }

            // open trace file
            QRCodeTrace.Open("QRCodeDecoderTrace.txt");
            QRCodeTrace.Write("QRCodeDecoderDemo");
                #endif

            // create decoder
            QRCodeDecoder = new QRDecoder();

            // resize window
            OnResize(sender, e);
            return;
        }
        /// <summary>
        /// Format result for display
        /// </summary>
        /// <param name="DataByteArray"></param>
        /// <returns></returns>
        private static string QRCodeResult
        (
            byte[][] DataByteArray
        )
        {
            // no QR code
            if (DataByteArray == null)
            {
                return(string.Empty);
            }

            // image has one QR code
            if (DataByteArray.Length == 1)
            {
                return(QRDecoder.ByteArrayToStr(DataByteArray[0]));
            }

            // image has more than one QR code
            StringBuilder Str = new StringBuilder();

            for (int Index = 0; Index < DataByteArray.Length; Index++)
            {
                if (Index != 0)
                {
                    Str.Append("\r\n");
                }
                Str.AppendFormat("QR Code {0}\r\n", Index + 1);
                Str.Append(QRDecoder.ByteArrayToStr(DataByteArray[Index]));
            }
            return(Str.ToString());
        }
예제 #6
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;
        }
        public static string GetQRCode(Bitmap imageToSearch)
        {
            //IL_000f: Unknown result type (might be due to invalid IL or missing references)
            //IL_0015: Expected O, but got Unknown
            //IL_0016: Unknown result type (might be due to invalid IL or missing references)
            //IL_001d: Expected O, but got Unknown
            //IL_001f: Unknown result type (might be due to invalid IL or missing references)
            //IL_0029: Expected O, but got Unknown
            //IL_0024: Unknown result type (might be due to invalid IL or missing references)
            //IL_002b: Expected O, but got Unknown
            //IL_0048: Unknown result type (might be due to invalid IL or missing references)
            //IL_004f: Expected O, but got Unknown
            if (false)
            {
                Dictionary <DecodeHintType, object> dictionary = new Dictionary <DecodeHintType, object>();
                QRCodeReader          val  = new QRCodeReader();
                BitmapLuminanceSource val2 = new BitmapLuminanceSource(imageToSearch);
                BinaryBitmap          val3 = new BinaryBitmap(new HybridBinarizer(val2));
                Result val4 = val.decode(val3);
                return((val4 != null) ? val4.Text : null);
            }
            QRDecoder val5 = new QRDecoder();

            byte[][] array = val5.ImageDecoder(imageToSearch);
            if (array == null)
            {
                return(null);
            }
            if (array.GetLength(0) > 0)
            {
                return(Encoding.UTF8.GetString(array[0]));
            }
            return(null);
        }
예제 #8
0
 public string Decode ( Image QR )
 {
     QRDecoder Decoder = new QRDecoder();
     byte [] [] Data = Decoder.ImageDecoder( (Bitmap) QR );
     if (Data == null)
         return null;
     string code = QRCode.ByteArrayToStr( Data [0] );
     return code;
 }
예제 #9
0
파일: Form1.cs 프로젝트: rosen1997/USP
        private void BTN_scan_Click(object sender, EventArgs e)
        {
            QRDecoder QRCodeDecoder = new QRDecoder();

            byte[][] DataByteArray = QRCodeDecoder.ImageDecoder((Bitmap)pictureBox1.Image);
            try
            {
                string Result = QRCode.ByteArrayToStr(DataByteArray[0]);
                //LBL_test.Text = Result;
            }
            catch { MessageBox.Show("Could not detect QR code!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
예제 #10
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;
        }
예제 #11
0
 private static void DecodeQrCode()
 {
     try
     {
         Image     image   = Image.Load("C:\\dev\\image4_out.jpg");
         QRDecoder decoder = new QRDecoder();
         var       qrCode  = decoder.ImageDecoder(image);
     }
     catch (Exception)
     {
         // handle exception here;
     }
 }
예제 #12
0
        public void LoadFilexUnitTest()
        {
            string demoFilePath = HelperUnitTest.GetDemoFile("image2.jpg");

            using (Bitmap bitmap = new Bitmap(demoFilePath))
            {
                QRDecoder decoder = new QRDecoder();
                var       qrCode  = decoder.ImageDecoder(bitmap);
                Assert.NotNull(qrCode);
                Assert.NotNull(qrCode.Results);
                Assert.Single(qrCode.Results);
            }
        }
예제 #13
0
 private static void test6()
 {
     try
     {
         using (Bitmap bitmap = new Bitmap("C:\\dev\\image4_out.jpg"))
         {
             QRDecoder decoder = new QRDecoder();
             var       qrCode  = decoder.ImageDecoder(bitmap);
             int       i       = 0;
         }
     }
     catch (Exception ex)
     {
         // handle exception here;
     }
 }
    public static async Task <string> ScanMediaAsync(this TelegramService telegramService)
    {
        var chatId = telegramService.ChatId;

        try
        {
            var op = Operation.Begin("Scanning Media from ChatId: {ChatId}", chatId);

            var message = telegramService.MessageOrEdited;

            if (message.Document == null &&
                message.Photo == null)
            {
                return(string.Empty);
            }

            var qrDecoder = telegramService.GetRequiredService <QRDecoder>();

            var qrFile = await telegramService.DownloadFileAsync("qr-reader");

            var image = await Image.LoadAsync(qrFile);

            var qrResult = qrDecoder.ImageDecoder(image);
            var data     = QRDecoder.ByteArrayToString(qrResult.FirstOrDefault());

            DirUtil.CleanCacheFiles(
                s =>
                s.Contains(chatId.ReduceChatId().ToString()) &&
                s.Contains("qr-reader")
                );

            op.Complete();

            return(data);
        }
        catch (Exception exception)
        {
            Log.Error(
                exception,
                "Error occured when Scan Media at ChatId {ChatId}",
                chatId
                );

            return(string.Empty);
        }
    }
예제 #15
0
        public MainWindow()
        {
            InitializeComponent();
            System.Drawing.Bitmap bi = new System.Drawing.Bitmap("qr2.png");

            Decoder = new QRDecoder();

            // call image decoder methos with <code>Bitmap</code> image of QRCode barcode
            byte[][] DataByteArray = Decoder.ImageDecoder(bi);
            // convert binary result to text string

            MessageBox.Show(DataByteArray.GetLength(0).ToString());// + "\n" + DataByteArray.GetLength(1).ToString());
            string Result = ByteArrayToStr(DataByteArray[0]);

            // string Result = ByteArrayToStr(DataByteArray[Index]);

            MessageBox.Show(Result);
            Clipboard.SetText(Result);
        }
        private string DecodeQRCode(Image image)
        {
            // create QR Code decoder object
            QRDecoder Decoder = new QRDecoder();

            // call image decoder methos with <code>Bitmap</code> image of QRCode barcode
            byte[][] DataByteArray = Decoder.ImageDecoder((Bitmap)image);

            // get the ECI Assignment value
            int ECIValue = Decoder.ECIAssignValue;

            if (ECIValue == -1)
            {
                // Assignment value not defined
            }
            else
            {
                // Assignment value between 0 to 999999
            }
            return(QRCodeResult(DataByteArray));
        }
예제 #17
0
        public bool validateTicket(BitmapImage img)
        {
            QRDecoder     decoder = new QRDecoder();
            BitmapEncoder encoder = new BmpBitmapEncoder();

            Byte[][] res;
            string   result = "";

            try
            {
                encoder.Frames.Add(BitmapFrame.Create(img));
                System.IO.MemoryStream outStream = new System.IO.MemoryStream();
                encoder.Save(outStream);
                System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(outStream);

                res = decoder.ImageDecoder(bitmap);
                foreach (byte[] temp in res)
                {
                    result = QRCode.ByteArrayToStr(temp);
                }
            }
            catch
            {
                return(false);
            }
            int    id = Int32.Parse(result);
            Ticket t  = en.Tickets.Where(x => x.TicketID == id).FirstOrDefault();

            if (t == null)
            {
                return(false);
            }
            DateTime ticketDate = (DateTime)t.TicketDate;

            if (DateTime.Now.DayOfYear - ticketDate.DayOfYear != 0 || t.TicketStatus == "Deleted")
            {
                return(false);
            }
            return(true);
        }
예제 #18
0
        /// <summary>
        /// Test decode program initialization
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event arguments</param>
        private void OnLoad(object sender, EventArgs e)
        {
#if DEBUG
            // current directory
            string CurDir  = Environment.CurrentDirectory;
            string WorkDir = CurDir.Replace("bin\\Debug", "Work");
            if (WorkDir != CurDir && Directory.Exists(WorkDir))
            {
                Environment.CurrentDirectory = WorkDir;
            }

            // open trace file
            // QRCodeTrace.Open("QRCodeDecoderTrace.txt");
            //QRCodeTrace.Write("QRCodeDecoderDemo");
#endif

            // create decoder
            QRCodeDecoder = new QRDecoder();

            // resize window
            OnResize(sender, e);
            return;
        }
예제 #19
0
파일: Form1.cs 프로젝트: rosen1997/USP
        private void buttonLess()
        {
            int flag = 0;

            for (int i = 0; i < 20; i++)
            {
                QRDecoder QRCodeDecoder = new QRDecoder();
                byte[][]  DataByteArray = QRCodeDecoder.ImageDecoder((Bitmap)pictureBox1.Image);
                try
                {
                    string Result = QRCode.ByteArrayToStr(DataByteArray[0]);
                    int    ID;
                    int.TryParse(Result, out ID);
                    flag = 1;

                    dbControl oDB = new dbControl(ID);
                    try
                    {
                        oDB.connectToDB();
                        oDB.writeToDB();
                        oDB.closeConnection();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

                    break;
                }
                catch { }
                wait(500);
            }
            if (flag == 0)
            {
                MessageBox.Show("Could not detect QR", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }
예제 #20
0
        public override Store Decode(Image QR)
        {
            QRDecoder Decoder = new QRDecoder();

            byte [] [] Data = Decoder.ImageDecoder((Bitmap)QR);
            if (Data == null)
            {
                return(null);
            }
            string code = QRCode.ByteArrayToStr(Data [0]);

            if (Check(code))
            {
                StoreJBuilder builder  = new StoreJBuilder(code);
                StoreDirector director = new StoreDirector();
                director.Construct(builder);
                Store s = builder.GetStore();
                return(s);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Program initialization
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event arguments</param>
        private void OnLoad(object sender, EventArgs e)
        {
            // program title
            Text = "QRCodeVideoDecoder - " + QRDecoder.VersionNumber + " \u00a9 2013-2018 Uzi Granot. All rights reserved.";

                #if DEBUG
            // current directory
            string CurDir  = Environment.CurrentDirectory;
            string WorkDir = CurDir.Replace("bin\\Debug", "Work");
            if (WorkDir != CurDir && Directory.Exists(WorkDir))
            {
                Environment.CurrentDirectory = WorkDir;
            }

            // open trace file
            QRCodeTrace.Open("QRCodeVideoDecoderTrace.txt");
            QRCodeTrace.Write(Text);
                #endif

            // disable reset button
            ResetButton.Enabled   = false;
            GoToUriButton.Enabled = false;

            // get an array of web camera devices
            DsDevice[] CameraDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);

            // make sure at least one is available
            if (CameraDevices == null || CameraDevices.Length == 0)
            {
                MessageBox.Show("No video cameras in this computer");
                Close();
                return;
            }

            // select the first camera
            DsDevice CameraDevice = CameraDevices[0];

            // Device moniker
            IMoniker CameraMoniker = CameraDevice.Moniker;

            // get a list of frame sizes available
            FrameSize[] FrameSizes = Camera.GetFrameSizeList(CameraMoniker);

            // make sure there is at least one frame size
            if (FrameSizes == null || FrameSizes.Length == 0)
            {
                MessageBox.Show("No video cameras in this computer");
                Close();
                return;
            }

            // test if our frame size is available
            int Index;
            for (Index = 0; Index < FrameSizes.Length &&
                 (FrameSizes[Index].Width != FrameSize.Width || FrameSizes[Index].Height != FrameSize.Height); Index++)
            {
                ;
            }

            // select first frame size
            if (Index == FrameSizes.Length)
            {
                FrameSize = FrameSizes[0];
            }

            // Set selected camera to camera control with default frame size
            // Create camera object
            VideoCamera = new Camera(PreviewPanel, CameraMoniker, FrameSize);

            // create QR code decoder
            Decoder = new QRDecoder();

            // resize window
            OnResize(sender, e);

            // create timer
            QRCodeTimer          = new Timer();
            QRCodeTimer.Interval = 200;
            QRCodeTimer.Tick    += QRCodeTimer_Tick;
            QRCodeTimer.Enabled  = true;
            return;
        }
예제 #22
0
 public QRAdapter()
 {
     _QRencoder = new QREncoder();
     _QRdecoder = new QRDecoder();
 }
예제 #23
0
 public static QrCodeResult ToResult(this QRDecoder decoder)
 {
     return(new QrCodeResult());
 }