using AForge.Video.DirectShow; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace XHZB.Desktop { /// /// CameraWindow.xaml 的交互逻辑 /// public partial class CameraWindow : Window { public CameraWindow() { InitializeComponent(); FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if(videoDevices.Count>0) { var videoDevice = new VideoCaptureDevice(videoDevices[0].MonikerString); videoDevice.VideoResolution = videoDevice.VideoCapabilities[0]; player.VideoSource = videoDevice; player.Start(); } } #region 窗体移动 /// /// 记录初始点 /// Point mPoint = new Point(0,0); bool IsStretching = false; int Position = 0; private void player_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { mPoint = new Point(e.X, e.Y); } private void player_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { if (IsStretching) { switch (Position) { case 1: this.Left = this.Left - (mPoint.X - e.X); this.Top = this.Top - (mPoint.Y - e.Y); this.Width = this.Width + (mPoint.X - e.X); this.Height = this.Height + (mPoint.Y - e.Y); break; case 2: this.Left = this.Left - (mPoint.X - e.X); this.Width = this.Width + (mPoint.X - e.X); this.Height = this.Height - (mPoint.Y - e.Y); mPoint = new Point(mPoint.X, e.Y); break; case 3: this.Top = this.Top - (mPoint.Y - e.Y); this.Width = this.Width - (mPoint.X - e.X); this.Height = this.Height + (mPoint.Y - e.Y); mPoint = new Point(e.X, mPoint.Y); break; case 4: this.Width = this.Width - (mPoint.X - e.X); this.Height = this.Height - (mPoint.Y - e.Y); mPoint = new Point(e.X, e.Y); break; default: break; } } else { this.Left = this.Left - (mPoint.X - e.X); this.Top = this.Top - (mPoint.Y - e.Y); } } if (e.Button == System.Windows.Forms.MouseButtons.None) { if (e.X <= 5 && e.Y <= 5)//左上 { IsStretching = true; Position = 1; wfhCamera.Cursor = Cursors.SizeNWSE; } else if (e.X <= 5 && e.Y >= wfhCamera.ActualHeight - 5)//左下 { IsStretching = true; Position = 2; wfhCamera.Cursor = Cursors.SizeNESW; } else if (e.X >= wfhCamera.ActualWidth - 5 && e.Y <= 5)//右上 { IsStretching = true; Position = 3; wfhCamera.Cursor = Cursors.SizeNESW; } else if (e.X >= wfhCamera.ActualWidth - 5 && e.Y >= wfhCamera.ActualHeight - 5)//右下 { IsStretching = true; Position = 4; wfhCamera.Cursor = Cursors.SizeNWSE; } else { IsStretching = false; wfhCamera.Cursor = Cursors.SizeAll; } } } #endregion } }