Exemple #1
0
        void cam_PreviewFrameAvailable(ICameraCaptureDevice device, object sender)
        {
            if (isProcessing)
            {
                return;
            }

            cameraDevice.PreviewFrameAvailable -= previewFrameHandler;

            isProcessing = true;

            int len = (int)device.PreviewResolution.Width * (int)device.PreviewResolution.Height;

            if (pixels == null)
            {
                pixels = new byte[len];
            }
            device.GetPreviewBufferY(pixels);
            // Byte[] result = new Byte[10000];
            int width  = (int)device.PreviewResolution.Width;
            int height = (int)device.PreviewResolution.Height;

            ThreadArguments ta = new ThreadArguments();

            ta.height = height;
            ta.width  = width;
            ta.pixels = pixels;


            Deployment.Current.Dispatcher.BeginInvoke(delegate()
            {
                bw.RunWorkerAsync(ta);
            });
        }
        private void PhotoCaptureDevice_PreviewFrameAvailable(ICameraCaptureDevice sender, object args)
        {
            if (_active && !_processing && _device != null)
            {
                _processing = true;
                _device.PreviewFrameAvailable -= PhotoCaptureDevice_PreviewFrameAvailable;

                var width  = (uint)_device.PreviewResolution.Width;
                var height = (uint)_device.PreviewResolution.Height;

                byte[] buffer = new byte[width * height];

                sender.GetPreviewBufferY(buffer);

                var frame = new Frame()
                {
                    Buffer     = buffer,
                    Pitch      = width,
                    Format     = FrameFormat.Gray8,
                    Dimensions = new Windows.Foundation.Size(width, height)
                };

                Dispatcher.BeginInvoke(async() =>
                {
                    if (_active)
                    {
                        var tuple = await ProcessFrameAsync(frame);

                        _processing = false;

                        if (_active && _device != null)
                        {
                            if (tuple != null && ResultTextBlock.Text != tuple.Item1.Text)
                            {
                                _resultTuple = tuple;

                                ResultTextBlock.Text = _resultTuple.Item1.Text;
                                ResultImage.Source   = _resultTuple.Item2;

                                if (OpticalReaderTask.Instance.RequireConfirmation)
                                {
                                    ResultGrid.Visibility = System.Windows.Visibility.Visible;
                                }
                                else
                                {
                                    NavigationService.GoBack();
                                }
                            }

                            _device.PreviewFrameAvailable += PhotoCaptureDevice_PreviewFrameAvailable;
                        }
                    }
                    else
                    {
                        _processing = false;
                    }
                });
            }
        }
        void cam_PreviewFrameAvailable(ICameraCaptureDevice device, object sender)
        {
            if (activeThreads >= param_maxThreads || resultDisplayed)
            {
                return;
            }


            if (isClosing)
            {
                return;
            }

            activeThreads++;

            System.Diagnostics.Debug.WriteLine("ActiveThreads: " + activeThreads.ToString());



            isProcessing = true;

            int len = (int)device.PreviewResolution.Width * (int)device.PreviewResolution.Height;

            if (pixels == null)
            {
                pixels = new byte[len];
            }
            device.GetPreviewBufferY(pixels);
            // Byte[] result = new Byte[10000];
            int width  = (int)device.PreviewResolution.Width;
            int height = (int)device.PreviewResolution.Height;

            ThreadArguments ta = new ThreadArguments();

            ta.height = height;
            ta.width  = width;
            ta.pixels = pixels;


            BackgroundWorker bw1 = new BackgroundWorker();

            bw1.WorkerReportsProgress      = false;
            bw1.WorkerSupportsCancellation = false;
            bw1.DoWork += new DoWorkEventHandler(bw_DoWork);
            bw1.RunWorkerAsync(ta);
        }
Exemple #4
0
        void cam_PreviewFrameAvailable(ICameraCaptureDevice device, object sender)
        {
            if (closeScanner)
            {
                closeScanner = false;
                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                    string resultString  = "{\"type\":" + JsonHelper.Serialize("Cancel") + "}";
                    PluginResult pResult = new PluginResult(PluginResult.Status.OK, resultString);
                    pResult.KeepCallback = true;
                    MWBarcodeScanner.mwbScanner.DispatchCommandResult(pResult, MWBarcodeScanner.kallbackID);
                    if (this.NavigationService.CanGoBack)
                    {
                        this.NavigationService.GoBack();
                    }
                    return;
                });
            }

            if (activeThreads >= param_maxThreads || resultDisplayed)
            {
                return;
            }


            if (isClosing)
            {
                return;
            }

            activeThreads++;

            // System.Diagnostics.Debug.WriteLine("ActiveThreads: " + activeThreads.ToString());

            isProcessing = true;

            int len = (int)device.PreviewResolution.Width * (int)device.PreviewResolution.Height;

            if (pixels == null)
            {
                pixels = new byte[len];
            }
            device.GetPreviewBufferY(pixels);
            // Byte[] result = new Byte[10000];
            int width  = (int)device.PreviewResolution.Width;
            int height = (int)device.PreviewResolution.Height;

            ThreadArguments ta = new ThreadArguments();

            ta.height = height;
            ta.width  = width;
            ta.pixels = pixels;


            BackgroundWorker bw1 = new BackgroundWorker();

            bw1.WorkerReportsProgress      = false;
            bw1.WorkerSupportsCancellation = false;
            bw1.DoWork += new DoWorkEventHandler(bw_DoWork);
            bw1.RunWorkerAsync(ta);
        }
        void cam_PreviewFrameAvailable(ICameraCaptureDevice device, object sender)
        {

            if (closeScanner) {
                closeScanner = false;
                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                   
                    string resultString = "{\"type\":" + JsonHelper.Serialize("Cancel") + "}";
                    PluginResult pResult = new PluginResult(PluginResult.Status.OK, resultString);
                    pResult.KeepCallback = true;
                    MWBarcodeScanner.mwbScanner.DispatchCommandResult(pResult, MWBarcodeScanner.kallbackID);
                    if (this.NavigationService.CanGoBack) { 
                        this.NavigationService.GoBack();
                    }
                   return;
               });
            }

            if (activeThreads >= param_maxThreads || resultDisplayed)
            {
                return;
            }


            if (isClosing)
            {
                return;
            }

            activeThreads++;

           // System.Diagnostics.Debug.WriteLine("ActiveThreads: " + activeThreads.ToString());

            isProcessing = true;

            int len = (int)device.PreviewResolution.Width * (int)device.PreviewResolution.Height;
            if (pixels == null)
                pixels = new byte[len];
            device.GetPreviewBufferY(pixels);
            // Byte[] result = new Byte[10000];
            int width = (int)device.PreviewResolution.Width;
            int height = (int)device.PreviewResolution.Height;

            ThreadArguments ta = new ThreadArguments();
            ta.height = height;
            ta.width = width;
            ta.pixels = pixels;


            BackgroundWorker bw1 = new BackgroundWorker();
            bw1.WorkerReportsProgress = false;
            bw1.WorkerSupportsCancellation = false;
            bw1.DoWork += new DoWorkEventHandler(bw_DoWork);
            bw1.RunWorkerAsync(ta);

        }
        private void PhotoCaptureDevice_PreviewFrameAvailable(ICameraCaptureDevice sender, object args)
        {
            if (_active && !_processing && _device != null)
            {
                _processing = true;
                _device.PreviewFrameAvailable -= PhotoCaptureDevice_PreviewFrameAvailable;

                var width = (uint)_device.PreviewResolution.Width;
                var height = (uint)_device.PreviewResolution.Height;

                byte[] buffer = new byte[width * height];

                sender.GetPreviewBufferY(buffer);

                var frame = new Frame()
                {
                    Buffer = buffer,
                    Pitch = width,
                    Format = FrameFormat.Gray8,
                    Dimensions = new Windows.Foundation.Size(width, height)
                };

                Dispatcher.BeginInvoke(async () =>
                {
                    if (_active)
                    {
                        var tuple = await ProcessFrameAsync(frame);

                        _processing = false;

                        if (_active && _device != null)
                        {
                            if (tuple != null && ResultTextBlock.Text != tuple.Item1.Text)
                            {
                                _resultTuple = tuple;

                                ResultTextBlock.Text = _resultTuple.Item1.Text;
                                ResultImage.Source = _resultTuple.Item2;

                                if (OpticalReaderTask.Instance.RequireConfirmation)
                                {
                                    ResultGrid.Visibility = System.Windows.Visibility.Visible;
                                }
                                else
                                {
                                    NavigationService.GoBack();
                                }
                            }

                            _device.PreviewFrameAvailable += PhotoCaptureDevice_PreviewFrameAvailable;
                        }
                    }
                    else
                    {
                        _processing = false;
                    }
                });
            }
        }
        void cam_PreviewFrameAvailable(ICameraCaptureDevice device, object sender)
        {

            if (activeThreads >= param_maxThreads || resultDisplayed)
            {
                return;
            }


            if (isClosing)
            {
                return;
            }

            activeThreads++;

            System.Diagnostics.Debug.WriteLine("ActiveThreads: " + activeThreads.ToString());

           

            

            isProcessing = true;

            int len = (int)device.PreviewResolution.Width * (int)device.PreviewResolution.Height;
            if (pixels == null)
                pixels = new byte[len];
            device.GetPreviewBufferY(pixels);
            // Byte[] result = new Byte[10000];
            int width = (int)device.PreviewResolution.Width;
            int height = (int)device.PreviewResolution.Height;

            ThreadArguments ta = new ThreadArguments();
            ta.height = height;
            ta.width = width;
            ta.pixels = pixels;


            BackgroundWorker bw1 = new BackgroundWorker();
            bw1.WorkerReportsProgress = false;
            bw1.WorkerSupportsCancellation = false;
            bw1.DoWork += new DoWorkEventHandler(bw_DoWork);
            bw1.RunWorkerAsync(ta);

        }
        void cam_PreviewFrameAvailable(ICameraCaptureDevice device, object sender)
        {

            if (isProcessing)
            {
                return;
            }

            cameraDevice.PreviewFrameAvailable -= previewFrameHandler;

            isProcessing = true;

            int len = (int)device.PreviewResolution.Width * (int)device.PreviewResolution.Height;
            if (pixels == null)
                pixels = new byte[len];
            device.GetPreviewBufferY(pixels);
            // Byte[] result = new Byte[10000];
            int width = (int)device.PreviewResolution.Width;
            int height = (int)device.PreviewResolution.Height;

            ThreadArguments ta = new ThreadArguments();
            ta.height = height;
            ta.width = width;
            ta.pixels = pixels;


            Deployment.Current.Dispatcher.BeginInvoke(delegate()
            {

                bw.RunWorkerAsync(ta);
            });

        }