Пример #1
0
        /// <summary>
        /// 点击拍照
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnTakePhoto_Click(object sender, RoutedEventArgs e)
        {
            //暂停
            VideoCapture.Pause();
            try
            {
                //抓取控件做成图片
                RenderTargetBitmap bmp = new RenderTargetBitmap((int)VideoCapture.NaturalVideoWidth, (int)VideoCapture.NaturalVideoHeight, 96, 96, PixelFormats.Default);
                //VideoCapture.Stretch = Stretch.Fill;
                VideoCapture.Measure(VideoCapture.RenderSize);
                VideoCapture.Arrange(new Rect(VideoCapture.RenderSize));
                bmp.Render(VideoCapture);
                BitmapEncoder encoder = new JpegBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bmp));

                UploadFile model = new UploadFile
                {
                    OrderId         = Order.Id,
                    IsSync          = false,
                    Status          = "Waitting",
                    ExecutionSystem = App.CurrentSystem,
                    FileName        = Order.GeneralFileName,
                    Location        = Order.AbsolutePath,
                    PhotoType       = Order.PhotoType
                };
                using (MemoryStream ms = new MemoryStream())
                {
                    encoder.Save(ms);
                    byte[] captureData = ms.ToArray();

                    File.WriteAllBytes(model.FileFullName, captureData);
                }

                model.InsertOrReplace();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                //继续开始摄像
                VideoCapture.Play();
            }
        }
Пример #2
0
        /// <summary>
        /// 拍照识别
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnPlay_Click(object sender, RoutedEventArgs e)
        {
            //抓取控件做成图片
            RenderTargetBitmap bmp = new RenderTargetBitmap((int)VideoCapture.NaturalVideoWidth, (int)VideoCapture.NaturalVideoHeight, 96, 96, PixelFormats.Default);

            //VideoCapture.Stretch = Stretch.Fill;
            VideoCapture.Measure(VideoCapture.RenderSize);
            VideoCapture.Arrange(new Rect(VideoCapture.RenderSize));
            bmp.Render(VideoCapture);
            BitmapEncoder encoder = new JpegBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(bmp));
            BarCodeScan scan = new BarCodeScan();

            using (MemoryStream ms = new MemoryStream())
            {
                encoder.Save(ms);
                Response <string> result = scan.GetBarCode(ms);
                if (!result.Success)
                {
                    MessageBox.Show(result.Errors, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    VideoCapture.Play();
                }
                else
                {
                    BarCode = result.Data;
                    if (string.IsNullOrEmpty(BarCode))
                    {
                        MessageBox.Show("No valid barcode was obtained,Please Retry", "Notice", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        VideoCapture.Pause();
                        Close();
                    }
                }
            }
        }