123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using TUCamera;
- using PaintDotNet.Base.SettingModel;
- using TUCAMAPI;
- namespace PaintDotNet.ImageCollect.CameraComponent
- {
- public partial class CommonRotateControl : UserControl
- {
- private TUCamera.TUCamera m_camera;
- private CameraParamModel m_cameraParamModel;
- private bool m_use;
- private static int _selectRotate;
- private static bool _mirrorH;
- private static bool _mirrorV;
- /// <summary>
- /// 图片旋转
- /// </summary>
- string[] m_rotateArray ;
- private void InitializeLanguageText()
- {
- 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") };
- this.groupBox1.Text = PdnResources.GetString("Menu.Imagerotation.text");
- this.ckbHorizontal.Text = PdnResources.GetString("Menu.Imagerotation.Horizontal.text");
- this.ckbVertical.Text = PdnResources.GetString("Menu.Imagerotation.Vertical.text");
- }
- public CommonRotateControl()
- {
- InitializeComponent();
- }
- public void Initialize(CameraParamModel model, bool use)
- {
- InitializeLanguageText();
- this.imgRotateComboBox.Items.Clear();
- this.imgRotateComboBox.Items.AddRange(m_rotateArray);
- imgRotateComboBox.MouseWheel += ImgRotateComboBox_MouseWheel;
- m_use = use;
- m_camera = TUCameraManager.GetInstance().GetCurrentCamera();
- m_cameraParamModel = model;
- _selectRotate = model.parame.Rotate;
- _mirrorH = model.parame.Horizontal != 0;
- _mirrorV = model.parame.Vertical != 0;
- UpdateDisplay();
- UpdateCam();
- this.GotFocus += CommonRotateControl_GotFocus; ;
- }
- private void CommonRotateControl_GotFocus(object sender, EventArgs e)
- {
- UpdateDisplay();
- }
- private void ImgRotateComboBox_MouseWheel(object sender, MouseEventArgs e)
- {
- var handle = e as HandledMouseEventArgs;
- handle.Handled = true;
- }
- private void imgRotateComboBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (_selectRotate == this.imgRotateComboBox.SelectedIndex)
- return;
- _selectRotate = this.imgRotateComboBox.SelectedIndex;
- m_cameraParamModel.parame.Rotate = _selectRotate;
- UpdateCam();
- }
- private void ckbHorizontal_CheckedChanged(object sender, EventArgs e)
- {
- m_cameraParamModel.parame.Horizontal = ckbHorizontal.Checked ? 1 : 0;
- _mirrorH = ckbHorizontal.Checked;
- }
- private void ckbVertical_CheckedChanged(object sender, EventArgs e)
- {
- m_cameraParamModel.parame.Vertical = ckbVertical.Checked ? 1 : 0;
- _mirrorV = ckbVertical.Checked;
- }
- private void ckbHorizontal_Click(object sender, EventArgs e)
- {
- UpdateCam();
- }
- private void UpdateCam()
- {
- int x = 0, y = 0, w = 2448, h = 2048;
- m_cameraParamModel.parame.previewRectX = 0;
- m_cameraParamModel.parame.previewRectY = 0;
- m_cameraParamModel.parame.previewRectW = w;
- m_cameraParamModel.parame.previewRectH = h;
- if (_selectRotate == 1)
- {
- m_cameraParamModel.parame.previewRectW = h;
- m_cameraParamModel.parame.previewRectH = w;
- m_camera.SetRotateL90();
- m_camera.SetROI(ref x, ref y, ref h, ref w);
- }
- else if (_selectRotate == 3)
- {
- m_cameraParamModel.parame.previewRectW = h;
- m_cameraParamModel.parame.previewRectH = w;
- m_camera.SetRotateR90();
- m_camera.SetROI(ref x, ref y, ref h, ref w);
- }
- else
- {
- m_camera.CancelRotate();
- m_camera.SetROI(ref x, ref y, ref w, ref h);
- }
- if (_selectRotate == 2)
- {
- m_camera.HorizontalMirrored = !_mirrorH;
- m_camera.VerticalMirrored = !_mirrorV;
- }
- else
- {
- m_camera.HorizontalMirrored = _mirrorH;
- m_camera.VerticalMirrored = _mirrorV;
- }
- }
- private void UpdateDisplay()
- {
- imgRotateComboBox.SelectedIndex = _selectRotate;
- ckbHorizontal.Checked = _mirrorH;
- ckbVertical.Checked = _mirrorV;
- }
- private void groupBox1_Enter(object sender, EventArgs e)
- {
- UpdateDisplay();
- }
- }
- }
|