Пример #1
0
 private void canvasPicture1_CreateBarcode(object sender, FrameEventArgs e)
 {
     CurrentBarcode = e.Frame;
     if (this.EncodingOptions == null)
     {
         this.EncodingOptions = GetEncodeOptions();
     }
     this.EncodingOptions.Width        = this.CurrentBarcode.Rect.Width;
     this.EncodingOptions.Height       = this.CurrentBarcode.Rect.Height;
     this.propertyGrid1.SelectedObject = this.EncodingOptions;
     this.pnlCreate.Enabled            = true;
 }
Пример #2
0
        public void ShowToolTip(ToolTip tooltip, BarcodeFrame frame)
        {
            PointF zoomPoint = this.ZoomedPoint(frame.StartPoint);

            if (frame.BarcodeFormat != 0)
            {
                tooltip.Show(frame.BarcodeFormat.ToString() + ":" + frame.RawText, this, Point.Round(zoomPoint), 1000);
            }
            else
            {
                tooltip.Show("認識できません。", this, Point.Round(zoomPoint), 1000);
            }
        }
Пример #3
0
 private void canvasPicture1_SelectedBarcode(object sender, FrameEventArgs e)
 {
     this.CurrentBarcode = e.Frame;
     if (this.EncodingOptions == null)
     {
         this.EncodingOptions = GetEncodeOptions();
     }
     this.EncodingOptions.Width        = this.CurrentBarcode.Rect.Width;
     this.EncodingOptions.Height       = this.CurrentBarcode.Rect.Height;
     this.propertyGrid1.SelectedObject = this.EncodingOptions;
     this.pnlCreate.Enabled            = true;
     this.canvasPicture1.ShowToolTip(toolTip1, this.CurrentBarcode);
     if (CurrentBarcode.BarcodeFormat != 0)
     {
         this.cmbEncoderType.SelectedValue = CurrentBarcode.BarcodeFormat;
         this.txtEncoderContent.Text       = CurrentBarcode.RawText;
     }
 }
Пример #4
0
        private void mnuEncode_Click(object sender, EventArgs e)
        {
            Image orgImg = this.canvasPicture1.Image;

            if (orgImg == null)
            {
                MessageBox.Show(this, "画像を選択してください");
                return;
            }
            int count = 0;

            if (canvasPicture1.Frames.Items.Count == 0)
            {
                Bitmap resultImg = (Bitmap)orgImg;
                BarcodeSDK.QRBarcodeReader QRReader = new BarcodeSDK.QRBarcodeReader();
                var results = QRReader.DecodeMultiple(resultImg);
                foreach (var result in results)
                {
                    if (result.IsSuccess && result.ResultRegion.HasValue)
                    {
                        Rectangle    rect  = result.ResultRegion.Value;
                        BarcodeFrame frame = new BarcodeFrame(result.ResultRegion.Value);
                        if (frame.IsTooSmall)
                        {
                            if (rect.Width < 8)
                            {
                                rect.Inflate(8, 0);
                            }
                            if (rect.Height < 8)
                            {
                                rect.Inflate(0, 8);
                            }
                            frame.Rect = rect;
                        }
                        frame.RawText       = result.RawText;
                        frame.BarcodeFormat = result.BarcodeFormat;
                        frame.CanCreate     = false;
                        this.canvasPicture1.Frames.Items.Add(frame);
                        this.canvasPicture1.Refresh();
                        count++;
                    }
                }
            }
            else
            {
                foreach (BarcodeFrame frame in this.canvasPicture1.Frames.Items)
                {
                    Bitmap resultImg = (Bitmap)orgImg;
                    if (frame.BarcodeImage == null)
                    {
                        BarcodeSDK.QRBarcodeReader QRReader = new BarcodeSDK.QRBarcodeReader();

                        Bitmap cutImg = (Bitmap)CutImage(frame.Rect, resultImg);
                        if (cutImg == null)
                        {
                            continue;
                        }
                        var result = QRReader.Decode(cutImg);
                        if (result.IsSuccess)
                        {
                            frame.RawText       = result.RawText;
                            frame.BarcodeFormat = result.BarcodeFormat;
                            frame.CanCreate     = false;
                            count++;
                        }
                    }
                }
            }
            MessageBox.Show(string.Format("認識完了しました。{0}件認識できました", count));
        }
Пример #5
0
 public FrameEventArgs(BarcodeFrame frame)
 {
     this.Frame = frame;
 }
Пример #6
0
        private void CanvasPicture_MouseUp(object sender, MouseEventArgs e)
        {
            if (!this.AllowAddFrame || !this.ShowFrames)
            {
                return;
            }

            if (e.Button == System.Windows.Forms.MouseButtons.Left && this.Selection != null)
            {
                if (!this.Selection.IsTooSmall)
                {
                    DrawXorFrame(this.Selection.Rect);
                }
                this.Selection.EndPoint = new Point(e.X, e.Y);
                if (!this.Selection.IsTooSmall)
                {
                    Rectangle rect = Selection.Rect;
                    DrawXorFrame(this.Selection.Rect);
                    //Create barcode
                    if (this.CreateBarcode != null)
                    {
                        Rectangle    unzoomRect = this.UnzoomRect(rect);
                        BarcodeFrame frame      = new BarcodeFrame(unzoomRect)
                        {
                            CanCreate = true
                        };
                        this.Frames.Items.Add(frame);
                        this.CreateBarcode(this, new FrameEventArgs(frame));
                    }
                    DrawXorFrame(this.Selection.Rect);
                    this.Refresh();
                    return;
                }
                else
                {
                    this.Selection = null;
                }
                if (this.MouseSelectEnd != null)
                {
                    this.MouseSelectEnd.Invoke(sender, e);
                }
            }
            Point        selPos = this.UnzoomPoint(new Point(e.X, e.Y));
            BarcodeFrame selFrm = this.Frames.GetFrameByPoint(selPos.X, selPos.Y);

            if (selFrm != null && (ModifierKeys & Keys.Control) == Keys.Control && e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                //Ctrlキー+Left Click(マルチ選択)
                selFrm.IsSelected = true;
                this.Refresh();
            }
            else if (selFrm != null && e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                //単一選択
                this.Frames.ClearSelection();
                selFrm.IsSelected = true;
                this.Refresh();
                if (this.SelectedBarcode != null)
                {
                    this.SelectedBarcode(this, new FrameEventArgs(selFrm));
                }
            }
            else if (selFrm == null && this.Frames.ToSelectedRects().Count > 0 && e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                this.Frames.ClearSelection();
                this.Refresh();
            }
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                Point clientPos = this.PointToScreen(new Point(e.X, e.Y));
                this.deleteMenuStrip.Show(clientPos);
            }
        }