CommonRotateControl.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using TUCamera;
  11. using PaintDotNet.Base.SettingModel;
  12. using TUCAMAPI;
  13. namespace PaintDotNet.ImageCollect.CameraComponent
  14. {
  15. public partial class CommonRotateControl : UserControl
  16. {
  17. private TUCamera.TUCamera m_camera;
  18. private CameraParamModel m_cameraParamModel;
  19. private bool m_use;
  20. private static int _selectRotate;
  21. private static bool _mirrorH;
  22. private static bool _mirrorV;
  23. /// <summary>
  24. /// 图片旋转
  25. /// </summary>
  26. string[] m_rotateArray ;
  27. private void InitializeLanguageText()
  28. {
  29. m_rotateArray = new string[] { PdnResources.GetString("Menu.original.text"), PdnResources.GetString("Menu.Edit.Rotate90CW.Text"), PdnResources.GetString("Menu.Edit.Rotate180.Text"), PdnResources.GetString("Menu.Rotate270degrees.Text") };
  30. this.groupBox1.Text = PdnResources.GetString("Menu.Imagerotation.text");
  31. this.ckbHorizontal.Text = PdnResources.GetString("Menu.Imagerotation.Horizontal.text");
  32. this.ckbVertical.Text = PdnResources.GetString("Menu.Imagerotation.Vertical.text");
  33. }
  34. public CommonRotateControl()
  35. {
  36. InitializeComponent();
  37. }
  38. public void Initialize(CameraParamModel model, bool use)
  39. {
  40. InitializeLanguageText();
  41. this.imgRotateComboBox.Items.Clear();
  42. this.imgRotateComboBox.Items.AddRange(m_rotateArray);
  43. imgRotateComboBox.MouseWheel += ImgRotateComboBox_MouseWheel;
  44. m_use = use;
  45. m_camera = TUCameraManager.GetInstance().GetCurrentCamera();
  46. m_cameraParamModel = model;
  47. _selectRotate = model.parame.Rotate;
  48. _mirrorH = model.parame.Horizontal != 0;
  49. _mirrorV = model.parame.Vertical != 0;
  50. UpdateDisplay();
  51. UpdateCam();
  52. this.GotFocus += CommonRotateControl_GotFocus; ;
  53. }
  54. private void CommonRotateControl_GotFocus(object sender, EventArgs e)
  55. {
  56. UpdateDisplay();
  57. }
  58. private void ImgRotateComboBox_MouseWheel(object sender, MouseEventArgs e)
  59. {
  60. var handle = e as HandledMouseEventArgs;
  61. handle.Handled = true;
  62. }
  63. private void imgRotateComboBox_SelectedIndexChanged(object sender, EventArgs e)
  64. {
  65. if (_selectRotate == this.imgRotateComboBox.SelectedIndex)
  66. return;
  67. _selectRotate = this.imgRotateComboBox.SelectedIndex;
  68. m_cameraParamModel.parame.Rotate = _selectRotate;
  69. UpdateCam();
  70. }
  71. private void ckbHorizontal_CheckedChanged(object sender, EventArgs e)
  72. {
  73. m_cameraParamModel.parame.Horizontal = ckbHorizontal.Checked ? 1 : 0;
  74. _mirrorH = ckbHorizontal.Checked;
  75. }
  76. private void ckbVertical_CheckedChanged(object sender, EventArgs e)
  77. {
  78. m_cameraParamModel.parame.Vertical = ckbVertical.Checked ? 1 : 0;
  79. _mirrorV = ckbVertical.Checked;
  80. }
  81. private void ckbHorizontal_Click(object sender, EventArgs e)
  82. {
  83. UpdateCam();
  84. }
  85. private void UpdateCam()
  86. {
  87. int x = 0, y = 0, w = 2448, h = 2048;
  88. m_cameraParamModel.parame.previewRectX = 0;
  89. m_cameraParamModel.parame.previewRectY = 0;
  90. m_cameraParamModel.parame.previewRectW = w;
  91. m_cameraParamModel.parame.previewRectH = h;
  92. if (_selectRotate == 1)
  93. {
  94. m_cameraParamModel.parame.previewRectW = h;
  95. m_cameraParamModel.parame.previewRectH = w;
  96. m_camera.SetRotateL90();
  97. m_camera.SetROI(ref x, ref y, ref h, ref w);
  98. }
  99. else if (_selectRotate == 3)
  100. {
  101. m_cameraParamModel.parame.previewRectW = h;
  102. m_cameraParamModel.parame.previewRectH = w;
  103. m_camera.SetRotateR90();
  104. m_camera.SetROI(ref x, ref y, ref h, ref w);
  105. }
  106. else
  107. {
  108. m_camera.CancelRotate();
  109. m_camera.SetROI(ref x, ref y, ref w, ref h);
  110. }
  111. if (_selectRotate == 2)
  112. {
  113. m_camera.HorizontalMirrored = !_mirrorH;
  114. m_camera.VerticalMirrored = !_mirrorV;
  115. }
  116. else
  117. {
  118. m_camera.HorizontalMirrored = _mirrorH;
  119. m_camera.VerticalMirrored = _mirrorV;
  120. }
  121. }
  122. private void UpdateDisplay()
  123. {
  124. imgRotateComboBox.SelectedIndex = _selectRotate;
  125. ckbHorizontal.Checked = _mirrorH;
  126. ckbVertical.Checked = _mirrorV;
  127. }
  128. private void groupBox1_Enter(object sender, EventArgs e)
  129. {
  130. UpdateDisplay();
  131. }
  132. }
  133. }