Example #1
0
        private void ShowResult()
        {
            Image  image          = null;
            string image_graphics = null;
            string read_result    = null;

            // 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)
            {
                image          = _currentResultInfo.Image;
                image_graphics = _currentResultInfo.ImageGraphics;
                read_result    = _currentResultInfo.ReadString;
            }

            if (image != null)
            {
                Size  image_size   = Gui.FitImageInControl(image.Size, picResultImage.Size);
                Image fitted_image = Gui.ResizeImageToBitmap(image, image_size);

                if (image_graphics != null)
                {
                    ResultGraphics rg = GraphicsResultParser.Parse(image_graphics, new Rectangle(0, 0, image_size.Width, image_size.Height));
                    Graphics       g  = Graphics.FromImage(fitted_image);

                    ResultGraphicsRenderer.PaintResults(g, rg);
                    g.Dispose();
                }

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

            if (read_result != null)
            {
                lbReadString.Text = read_result;
            }
        }
Example #2
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);
            }
        }
Example #3
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);
                }
            }