Ejemplo n.º 1
0
 private void Camera_ImageArrived(object sender, ImageArrivedEventArgs args)
 {
     if (ImageArrived != null)
     {
         ImageArrived(this, args);
     }
 }
Ejemplo n.º 2
0
        private void Camera_ImageArrived_UIThread(object source, ImageArrivedEventArgs args)
        {
            var bitmap = LoadBitmap(args.Bitmap);

            image.Width  = bitmap.Width;
            image.Height = bitmap.Height;
            image.Source = bitmap;
        }
        private void OnImageArrived(object sender, ImageArrivedEventArgs args)
        {
            // If the current result info has the same result ID as the one we've just
            // received, store the image in it, otherwise create a new result info object.
            lock (_currentResultInfoSyncLock)
            {
                if (_resultCache.ContainsKey(args.ResultId))
                {
                    _resultCache[args.ResultId].Image = args.Image;
                }
                else
                {
                    _resultCache.Add(args.ResultId, new ResultInfo(args.ResultId, args.Image, null, null, null));
                }

                ProcessResultQueue();
            }
        }
Ejemplo n.º 4
0
        private void OnImageArrived(object sender, ImageArrivedEventArgs args)
        {
            // If the current result info has the same result ID as the one we've just
            // received, store the image in it, otherwise create a new result info object.
            lock (_currentResultInfoSyncLock)
            {
                if (_currentResultInfo.ResultId == args.ResultId)
                {
                    _currentResultInfo.Image = args.Image;
                }
                else
                {
                    _currentResultInfo = new ResultInfo(args.ResultId, args.Image, null, null);
                }
            }

            _syncContext.Post(
                delegate
            {
                AddListItem("Image arrived (rid=" + args.ResultId.ToString() + "), size = " + args.Image.Width.ToString() + "x" + args.Image.Height.ToString());
                ShowResult();
            },
                null);
        }
Ejemplo n.º 5
0
        private void ShowResult(ComplexResult complexResult)
        {
            List <Image>  images            = new List <Image>();
            List <string> image_graphics    = new List <string>();
            string        read_result       = null;
            int           result_id         = -1;
            ResultTypes   collected_results = ResultTypes.None;

            // Take a reference or copy values from the locked result info object. This is done
            // so that the lock is used only for a short period of time.
            lock (_currentResultInfoSyncLock)
            {
                foreach (var simple_result in complexResult.SimpleResults)
                {
                    collected_results |= simple_result.Id.Type;

                    switch (simple_result.Id.Type)
                    {
                    case ResultTypes.Image:
                        Image image = ImageArrivedEventArgs.GetImageFromImageBytes(simple_result.Data);
                        if (image != null)
                        {
                            images.Add(image);
                        }
                        break;

                    case ResultTypes.ImageGraphics:
                        image_graphics.Add(simple_result.GetDataAsString());
                        break;

                    case ResultTypes.ReadXml:
                        read_result = GetReadStringFromResultXml(simple_result.GetDataAsString());
                        result_id   = simple_result.Id.Id;
                        break;

                    case ResultTypes.ReadString:
                        read_result = simple_result.GetDataAsString();
                        result_id   = simple_result.Id.Id;
                        break;
                    }
                }
            }

            AddListItem(string.Format("Complex result arrived: resultId = {0}, read result = {1}", result_id, read_result));
            Log("Complex result contains", string.Format("{0}", collected_results.ToString()));

            if (images.Count > 0)
            {
                Image first_image = images[0];

                Size  image_size   = Gui.FitImageInControl(first_image.Size, picResultImage.Size);
                Image fitted_image = Gui.ResizeImageToBitmap(first_image, image_size);

                if (image_graphics.Count > 0)
                {
                    using (Graphics g = Graphics.FromImage(fitted_image))
                    {
                        foreach (var graphics in image_graphics)
                        {
                            ResultGraphics rg = GraphicsResultParser.Parse(graphics, new Rectangle(0, 0, image_size.Width, image_size.Height));
                            ResultGraphicsRenderer.PaintResults(g, rg);
                        }
                    }
                }

                if (picResultImage.Image != null)
                {
                    var image = picResultImage.Image;
                    picResultImage.Image = null;
                    image.Dispose();
                }

                picResultImage.Image = fitted_image;
                picResultImage.Invalidate();
            }

            if (read_result != null && !_cbEmulateEnabled)
            {
                lbReadString.Text = read_result;
            }
            if (_cbEmulateEnabled)
            {
                SendKeys.Send(read_result);
            }
        }
Ejemplo n.º 6
0
            private void Results_ComplexResultCompleted(object sender, ComplexResult e)
            {
                List <Image>  images            = new List <Image>();
                List <string> image_graphics    = new List <string>();
                string        read_result       = null;
                int           result_id         = -1;
                int           barcodeCount      = 0;
                ResultTypes   collected_results = ResultTypes.None;

                foreach (var simple_result in e.SimpleResults)
                {
                    collected_results |= simple_result.Id.Type;
                    switch (simple_result.Id.Type)
                    {
                    case ResultTypes.Image:
                        Image image = ImageArrivedEventArgs.GetImageFromImageBytes(simple_result.Data);
                        if (image != null)
                        {
                            images.Add(image);
                        }
                        break;

                    case ResultTypes.ImageGraphics:
                        image_graphics.Add(simple_result.GetDataAsString());
                        break;

                    case ResultTypes.ReadXml:
                        read_result = GetReadStringFromResultXml(simple_result.GetDataAsString());
                        result_id   = simple_result.Id.Id;
                        break;

                    case ResultTypes.ReadString:
                        read_result = simple_result.GetDataAsString();
                        result_id   = simple_result.Id.Id;
                        break;
                    }
                }

                //BarcodeDetect?.Invoke(read_result.Split('\n').Length.ToString());
                barcodeCount = Regex.Matches(read_result, "$", RegexOptions.Multiline).Count;
                //TransferImage flag
                bool transferImageFlag = _allTimeTransferImage || (PctByScan != barcodeCount);

                if (images.Count > 0)
                {
                    Image first_image  = images[0];
                    Size  image_size   = Gui.FitImageInControl(first_image.Size, PictureSize);
                    Image fitted_image = Gui.ResizeImageToBitmap(first_image, image_size);

                    if (image_graphics.Count > 0)
                    {
                        using (Graphics g = Graphics.FromImage(fitted_image))
                        {
                            foreach (var graphics in image_graphics)
                            {
                                ResultGraphics rg = GraphicsResultParser.Parse(graphics, new Rectangle(0, 0, image_size.Width, image_size.Height));
                                ResultGraphicsRenderer.PaintResults(g, rg);
                            }
                        }
                    }
                    string myPath = _path + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
                    if (transferImageFlag)
                    {
                        fitted_image.Save(myPath);
                    }
                    PictureSaved?.Invoke(fitted_image, myPath);
                }

                if (PctByScan != barcodeCount)
                {
                    BarcodeDetectFailed?.Invoke(read_result);
                }
                else
                {
                    BarcodeDetectOK?.Invoke(read_result);
                }
            }
Ejemplo n.º 7
0
 private void Camera_ImageArrived(object source, ImageArrivedEventArgs args)
 {
     Dispatcher.BeginInvoke((ThreadStart)(() => Camera_ImageArrived_UIThread(source, args)));
 }