Exemplo n.º 1
0
        /// <summary>
        /// 从文件夹选择图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSelect_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog
            {
                Multiselect = true,
                Filter      = "图片文件(*.png;*.jpg;*.bmp;*.jpeg)|*.png;*.jpg;*.bmp;*.jpeg"
            };

            try
            {
                if (openFile.ShowDialog() == true)
                {
                    foreach (string item in openFile.FileNames)
                    {
                        UploadFile model = new UploadFile
                        {
                            OrderId         = Order.Id,
                            IsSync          = false,
                            Status          = "Waitting",
                            ExecutionSystem = App.CurrentSystem,
                            FileName        = Order.GeneralFileName,
                            Location        = Order.AbsolutePath,
                            PhotoType       = Order.PhotoType
                        };

                        File.Copy(item, model.FileFullName, true);
                        model.InsertOrReplace();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
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();
            }
        }