星火直播PC
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using AForge.Video.DirectShow;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Shapes;
  15. namespace XHZB.Desktop
  16. {
  17. /// <summary>
  18. /// CameraWindow.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class CameraWindow : Window
  21. {
  22. public CameraWindow()
  23. {
  24. InitializeComponent();
  25. FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
  26. if(videoDevices.Count>0)
  27. {
  28. var videoDevice = new VideoCaptureDevice(videoDevices[0].MonikerString);
  29. videoDevice.VideoResolution = videoDevice.VideoCapabilities[0];
  30. player.VideoSource = videoDevice;
  31. player.Start();
  32. }
  33. }
  34. #region 窗体移动
  35. /// <summary>
  36. /// 记录初始点
  37. /// </summary>
  38. Point mPoint = new Point(0,0);
  39. bool IsStretching = false;
  40. int Position = 0;
  41. private void player_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  42. {
  43. mPoint = new Point(e.X, e.Y);
  44. }
  45. private void player_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
  46. {
  47. if (e.Button == System.Windows.Forms.MouseButtons.Left)
  48. {
  49. if (IsStretching)
  50. {
  51. switch (Position)
  52. {
  53. case 1:
  54. this.Left = this.Left - (mPoint.X - e.X);
  55. this.Top = this.Top - (mPoint.Y - e.Y);
  56. this.Width = this.Width + (mPoint.X - e.X);
  57. this.Height = this.Height + (mPoint.Y - e.Y);
  58. break;
  59. case 2:
  60. this.Left = this.Left - (mPoint.X - e.X);
  61. this.Width = this.Width + (mPoint.X - e.X);
  62. this.Height = this.Height - (mPoint.Y - e.Y);
  63. mPoint = new Point(mPoint.X, e.Y);
  64. break;
  65. case 3:
  66. this.Top = this.Top - (mPoint.Y - e.Y);
  67. this.Width = this.Width - (mPoint.X - e.X);
  68. this.Height = this.Height + (mPoint.Y - e.Y);
  69. mPoint = new Point(e.X, mPoint.Y);
  70. break;
  71. case 4:
  72. this.Width = this.Width - (mPoint.X - e.X);
  73. this.Height = this.Height - (mPoint.Y - e.Y);
  74. mPoint = new Point(e.X, e.Y);
  75. break;
  76. default:
  77. break;
  78. }
  79. }
  80. else
  81. {
  82. this.Left = this.Left - (mPoint.X - e.X);
  83. this.Top = this.Top - (mPoint.Y - e.Y);
  84. }
  85. }
  86. if (e.Button == System.Windows.Forms.MouseButtons.None)
  87. {
  88. if (e.X <= 5 && e.Y <= 5)//左上
  89. {
  90. IsStretching = true;
  91. Position = 1;
  92. wfhCamera.Cursor = Cursors.SizeNWSE;
  93. }
  94. else if (e.X <= 5 && e.Y >= wfhCamera.ActualHeight - 5)//左下
  95. {
  96. IsStretching = true;
  97. Position = 2;
  98. wfhCamera.Cursor = Cursors.SizeNESW;
  99. }
  100. else if (e.X >= wfhCamera.ActualWidth - 5 && e.Y <= 5)//右上
  101. {
  102. IsStretching = true;
  103. Position = 3;
  104. wfhCamera.Cursor = Cursors.SizeNESW;
  105. }
  106. else if (e.X >= wfhCamera.ActualWidth - 5 && e.Y >= wfhCamera.ActualHeight - 5)//右下
  107. {
  108. IsStretching = true;
  109. Position = 4;
  110. wfhCamera.Cursor = Cursors.SizeNWSE;
  111. }
  112. else
  113. {
  114. IsStretching = false;
  115. wfhCamera.Cursor = Cursors.SizeAll;
  116. }
  117. }
  118. }
  119. #endregion
  120. }
  121. }