星火微课系统客户端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

MainImage.cs 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. using ComeCapture.Models;
  2. using Common.system;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Controls.Primitives;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Shapes;
  11. namespace ComeCapture.Controls
  12. {
  13. public class MainImage : Control
  14. {
  15. public Point point;
  16. private Rectangle _Rectangle = null;
  17. private Ellipse _Ellipse = null;
  18. private List<Point> points = null;
  19. private Path _Line = null;
  20. private readonly StreamGeometry geometry = new StreamGeometry();
  21. public TextBoxControl _Text = null;
  22. private Path _Arrow = null;
  23. static MainImage()
  24. {
  25. DefaultStyleKeyProperty.OverrideMetadata(typeof(MainImage), new FrameworkPropertyMetadata(typeof(MainImage)));
  26. }
  27. public MainImage()
  28. {
  29. _Current = this;
  30. AddHandler(Thumb.DragStartedEvent, new DragStartedEventHandler(OnDragStart));
  31. AddHandler(Thumb.DragCompletedEvent, new DragCompletedEventHandler(OnDragCompleted));
  32. AddHandler(Thumb.DragDeltaEvent, new DragDeltaEventHandler(OnDragDelta));
  33. AddHandler(MouseMoveEvent, new MouseEventHandler(OnMove));
  34. Limit = new Limit();
  35. }
  36. #region 属性 Current
  37. private static MainImage _Current = null;
  38. public static MainImage Current
  39. {
  40. get => _Current;
  41. set => _Current = value;
  42. }
  43. #endregion 属性 Current
  44. #region MoveCursor DependencyProperty
  45. public Cursor MoveCursor
  46. {
  47. get => (Cursor)GetValue(MoveCursorProperty);
  48. set => SetValue(MoveCursorProperty, value);
  49. }
  50. public static readonly DependencyProperty MoveCursorProperty =
  51. DependencyProperty.Register("MoveCursor", typeof(Cursor), typeof(MainImage),
  52. new PropertyMetadata(Cursors.SizeAll, new PropertyChangedCallback(MainImage.OnMoveCursorPropertyChanged)));
  53. private static void OnMoveCursorPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
  54. {
  55. if (obj is MainImage)
  56. {
  57. (obj as MainImage).OnMoveCursorValueChanged();
  58. }
  59. }
  60. protected void OnMoveCursorValueChanged()
  61. {
  62. }
  63. #endregion MoveCursor DependencyProperty
  64. #region Direction DependencyProperty
  65. public Direction Direction
  66. {
  67. get => (Direction)GetValue(DirectionProperty);
  68. set => SetValue(DirectionProperty, value);
  69. }
  70. public static readonly DependencyProperty DirectionProperty =
  71. DependencyProperty.Register("Direction", typeof(Direction), typeof(MainImage),
  72. new PropertyMetadata(Direction.Null, new PropertyChangedCallback(MainImage.OnDirectionPropertyChanged)));
  73. private static void OnDirectionPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
  74. {
  75. if (obj is MainImage)
  76. {
  77. (obj as MainImage).OnDirectionValueChanged();
  78. }
  79. }
  80. protected void OnDirectionValueChanged()
  81. {
  82. }
  83. #endregion Direction DependencyProperty
  84. #region Limit DependencyProperty
  85. public Limit Limit
  86. {
  87. get => (Limit)GetValue(LimitProperty);
  88. set => SetValue(LimitProperty, value);
  89. }
  90. public static readonly DependencyProperty LimitProperty =
  91. DependencyProperty.Register("Limit", typeof(Limit), typeof(MainImage),
  92. new PropertyMetadata(null, new PropertyChangedCallback(MainImage.OnLimitPropertyChanged)));
  93. private static void OnLimitPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
  94. {
  95. if (obj is MainImage)
  96. {
  97. (obj as MainImage).OnLimitValueChanged();
  98. }
  99. }
  100. protected void OnLimitValueChanged()
  101. {
  102. }
  103. #endregion Limit DependencyProperty
  104. #region ZoomThumbVisibility DependencyProperty
  105. public Visibility ZoomThumbVisibility
  106. {
  107. get => (Visibility)GetValue(ZoomThumbVisibilityProperty);
  108. set => SetValue(ZoomThumbVisibilityProperty, value);
  109. }
  110. public static readonly DependencyProperty ZoomThumbVisibilityProperty =
  111. DependencyProperty.Register("ZoomThumbVisibility", typeof(Visibility), typeof(MainImage),
  112. new PropertyMetadata(Visibility.Visible, new PropertyChangedCallback(MainImage.OnZoomThumbVisibilityPropertyChanged)));
  113. private static void OnZoomThumbVisibilityPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
  114. {
  115. if (obj is MainImage)
  116. {
  117. (obj as MainImage).OnZoomThumbVisibilityValueChanged();
  118. }
  119. }
  120. protected void OnZoomThumbVisibilityValueChanged()
  121. {
  122. }
  123. #endregion ZoomThumbVisibility DependencyProperty
  124. #region 开始滑动事件
  125. private void OnDragStart(object sender, DragStartedEventArgs e)
  126. {
  127. Direction = (e.OriginalSource as ZoomThumb).Direction;
  128. if (SizeColorBar.Current.Selected != Tool.Null)
  129. {
  130. point = Mouse.GetPosition(this);
  131. if (SizeColorBar.Current.Selected == Tool.Text)
  132. {
  133. DrawText();
  134. }
  135. }
  136. }
  137. #endregion 开始滑动事件
  138. #region 滑动中事件
  139. private void OnDragDelta(object sender, DragDeltaEventArgs e)
  140. {
  141. double X = e.HorizontalChange;
  142. double Y = e.VerticalChange;
  143. switch (Direction)
  144. {
  145. case Direction.Move:
  146. if (SizeColorBar.Current.Selected == Tool.Null)
  147. {
  148. OnMove(X, Y);
  149. }
  150. else
  151. {
  152. switch (SizeColorBar.Current.Selected)
  153. {
  154. case Tool.Rectangle:
  155. DrawRectangle(X, Y);
  156. break;
  157. case Tool.Ellipse:
  158. DrawEllipse(X, Y);
  159. break;
  160. case Tool.Arrow:
  161. DrawArrow(X, Y);
  162. break;
  163. case Tool.Line:
  164. DrawLine(X, Y);
  165. break;
  166. case Tool.Text:
  167. break;
  168. default:
  169. break;
  170. }
  171. }
  172. break;
  173. case Direction.Null:
  174. break;
  175. default:
  176. string str = Direction.ToString();
  177. if (X != 0)
  178. {
  179. if (str.Contains("Left"))
  180. {
  181. Left(X);
  182. }
  183. if (str.Contains("Right"))
  184. {
  185. Right(X);
  186. }
  187. }
  188. if (Y != 0)
  189. {
  190. if (str.Contains("Top"))
  191. {
  192. Top(Y);
  193. }
  194. if (str.Contains("Bottom"))
  195. {
  196. Bottom(Y);
  197. }
  198. }
  199. AppModel.Current.ChangeShowSize();
  200. break;
  201. }
  202. ImageEditBar.Current.ResetCanvas();
  203. SizeColorBar.Current.ResetCanvas();
  204. }
  205. #endregion 滑动中事件
  206. #region 滑动结束事件
  207. private void OnDragCompleted(object sender, DragCompletedEventArgs e)
  208. {
  209. if (Direction == Direction.Move && SizeColorBar.Current.Selected != Tool.Null)
  210. {
  211. switch (SizeColorBar.Current.Selected)
  212. {
  213. case Tool.Rectangle:
  214. if (_Rectangle != null)
  215. {
  216. ResetLimit(Canvas.GetLeft(_Rectangle), Canvas.GetTop(_Rectangle), Canvas.GetLeft(_Rectangle) + _Rectangle.Width, Canvas.GetTop(_Rectangle) + _Rectangle.Height);
  217. JieTuWindow.Register(_Rectangle);
  218. _Rectangle = null;
  219. }
  220. break;
  221. case Tool.Ellipse:
  222. if (_Ellipse != null)
  223. {
  224. ResetLimit(Canvas.GetLeft(_Ellipse), Canvas.GetTop(_Ellipse), Canvas.GetLeft(_Ellipse) + _Ellipse.Width, Canvas.GetTop(_Ellipse) + _Ellipse.Height);
  225. JieTuWindow.Register(_Ellipse);
  226. _Ellipse = null;
  227. }
  228. break;
  229. case Tool.Arrow:
  230. if (_Arrow != null)
  231. {
  232. geometry.Clear();
  233. ResetLimit(points.Min(p => p.X), points.Min(p => p.Y), points.Max(p => p.X), points.Max(p => p.Y));
  234. points = null;
  235. JieTuWindow.Register(_Arrow);
  236. _Arrow = null;
  237. }
  238. break;
  239. case Tool.Line:
  240. if (_Line != null)
  241. {
  242. geometry.Clear();
  243. ResetLimit(points.Min(p => p.X), points.Min(p => p.Y), points.Max(p => p.X), points.Max(p => p.Y));
  244. points = null;
  245. JieTuWindow.Register(_Line);
  246. _Line = null;
  247. }
  248. break;
  249. case Tool.Text:
  250. break;
  251. default:
  252. break;
  253. }
  254. }
  255. Direction = Direction.Null;
  256. }
  257. #endregion 滑动结束事件
  258. #region 画矩形
  259. private void DrawRectangle(double X, double Y)
  260. {
  261. if (_Rectangle == null)
  262. {
  263. _Rectangle = new Rectangle()
  264. {
  265. Fill = new SolidColorBrush(Colors.Transparent),
  266. Stroke = RectangleTool.Current.LineBrush,
  267. StrokeThickness = RectangleTool.Current.LineThickness
  268. };
  269. Panel.SetZIndex(_Rectangle, -1);
  270. JieTuWindow.AddControl(_Rectangle);
  271. }
  272. if (X > 0)
  273. {
  274. Canvas.SetLeft(_Rectangle, point.X + AppModel.Current.MaskLeftWidth);
  275. _Rectangle.Width = X < Width - point.X ? X : Width - point.X;
  276. }
  277. else
  278. {
  279. Canvas.SetLeft(_Rectangle, -X < point.X ? point.X + X + AppModel.Current.MaskLeftWidth : AppModel.Current.MaskLeftWidth);
  280. _Rectangle.Width = -X < point.X ? -X : point.X;
  281. }
  282. if (Y > 0)
  283. {
  284. Canvas.SetTop(_Rectangle, point.Y + AppModel.Current.MaskTopHeight);
  285. _Rectangle.Height = Y < Height - point.Y ? Y : Height - point.Y;
  286. }
  287. else
  288. {
  289. Canvas.SetTop(_Rectangle, -Y < point.Y ? point.Y + Y + AppModel.Current.MaskTopHeight : AppModel.Current.MaskTopHeight);
  290. _Rectangle.Height = -Y < point.Y ? -Y : point.Y;
  291. }
  292. }
  293. #endregion 画矩形
  294. #region 画椭圆
  295. private void DrawEllipse(double X, double Y)
  296. {
  297. if (_Ellipse == null)
  298. {
  299. _Ellipse = new Ellipse()
  300. {
  301. Fill = new SolidColorBrush(Colors.Transparent),
  302. Stroke = EllipseTool.Current.LineBrush,
  303. StrokeThickness = EllipseTool.Current.LineThickness
  304. };
  305. Panel.SetZIndex(_Ellipse, -1);
  306. JieTuWindow.AddControl(_Ellipse);
  307. }
  308. if (X > 0)
  309. {
  310. Canvas.SetLeft(_Ellipse, point.X + AppModel.Current.MaskLeftWidth);
  311. _Ellipse.Width = X < Width - point.X ? X : Width - point.X;
  312. }
  313. else
  314. {
  315. Canvas.SetLeft(_Ellipse, -X < point.X ? point.X + X + AppModel.Current.MaskLeftWidth : AppModel.Current.MaskLeftWidth);
  316. _Ellipse.Width = -X < point.X ? -X : point.X;
  317. }
  318. if (Y > 0)
  319. {
  320. Canvas.SetTop(_Ellipse, point.Y + AppModel.Current.MaskTopHeight);
  321. _Ellipse.Height = Y < Height - point.Y ? Y : Height - point.Y;
  322. }
  323. else
  324. {
  325. Canvas.SetTop(_Ellipse, -Y < point.Y ? point.Y + Y + AppModel.Current.MaskTopHeight : AppModel.Current.MaskTopHeight);
  326. _Ellipse.Height = -Y < point.Y ? -Y : point.Y;
  327. }
  328. }
  329. #endregion 画椭圆
  330. #region 画箭头
  331. private void DrawArrow(double X, double Y)
  332. {
  333. Point screen = new Point(point.X + AppModel.Current.MaskLeftWidth, point.Y + AppModel.Current.MaskTopHeight);
  334. if (_Arrow == null)
  335. {
  336. _Arrow = new Path()
  337. {
  338. Fill = ArrowTool.Current.LineBrush,
  339. StrokeThickness = ArrowTool.Current.LineThickness
  340. };
  341. Panel.SetZIndex(_Arrow, -1);
  342. JieTuWindow.AddControl(_Arrow);
  343. }
  344. Point point2 = new Point(screen.X + X, screen.Y + Y);
  345. point2.X = point2.X < AppModel.Current.MaskLeftWidth ? AppModel.Current.MaskLeftWidth : point2.X > AppModel.Current.MaskLeftWidth + Width ? AppModel.Current.MaskLeftWidth + Width : point2.X;
  346. point2.Y = point2.Y < AppModel.Current.MaskTopHeight ? AppModel.Current.MaskTopHeight : point2.Y > AppModel.Current.MaskTopHeight + Height ? AppModel.Current.MaskTopHeight + Height : point2.Y;
  347. points = ArrowTool.Current.CreateArrow(screen, point2);
  348. using (StreamGeometryContext ctx = geometry.Open())
  349. {
  350. for (int i = 0; i < points.Count; i++)
  351. {
  352. if (i == 0)
  353. {
  354. ctx.BeginFigure(points[0], true, false);
  355. }
  356. else
  357. {
  358. ctx.LineTo(points[i], true, true);
  359. }
  360. }
  361. }
  362. _Arrow.Data = geometry.Clone();
  363. }
  364. #endregion 画箭头
  365. #region 画刷
  366. private void DrawLine(double X, double Y)
  367. {
  368. Point screen = new Point(point.X + AppModel.Current.MaskLeftWidth, point.Y + AppModel.Current.MaskTopHeight);
  369. if (_Line == null)
  370. {
  371. _Line = new Path()
  372. {
  373. Stroke = LineTool.Current.LineBrush,
  374. StrokeThickness = LineTool.Current.LineThickness
  375. };
  376. points = new List<Point>
  377. {
  378. screen
  379. };
  380. Panel.SetZIndex(_Line, -1);
  381. JieTuWindow.AddControl(_Line);
  382. }
  383. Point point2 = new Point(screen.X + X, screen.Y + Y);
  384. point2.X = point2.X < AppModel.Current.MaskLeftWidth ? AppModel.Current.MaskLeftWidth : point2.X > AppModel.Current.MaskLeftWidth + Width ? AppModel.Current.MaskLeftWidth + Width : point2.X;
  385. point2.Y = point2.Y < AppModel.Current.MaskTopHeight ? AppModel.Current.MaskTopHeight : point2.Y > AppModel.Current.MaskTopHeight + Height ? AppModel.Current.MaskTopHeight + Height : point2.Y;
  386. points.Add(point2);
  387. using (StreamGeometryContext ctx = geometry.Open())
  388. {
  389. for (int i = 0; i < points.Count; i++)
  390. {
  391. if (i == 0)
  392. {
  393. ctx.BeginFigure(points[0], true, false);
  394. }
  395. else
  396. {
  397. ctx.LineTo(points[i], true, true);
  398. }
  399. }
  400. }
  401. _Line.Data = geometry.Clone();
  402. }
  403. #endregion 画刷
  404. #region 添加输入框
  405. private void DrawText()
  406. {
  407. if (_Text != null)
  408. {
  409. Focus();
  410. }
  411. else
  412. {
  413. _Text = new TextBoxControl()
  414. {
  415. FontSize = TextTool.Current.FontSize,
  416. Foreground = TextTool.Current.LineBrush
  417. };
  418. if (point.X > Width - 36)
  419. {
  420. point.X = Width - 36;
  421. }
  422. if (point.Y > Height - 22)
  423. {
  424. point.Y = Height - 22;
  425. }
  426. Point screen = new Point(point.X + AppModel.Current.MaskLeftWidth, point.Y + AppModel.Current.MaskTopHeight);
  427. Canvas.SetLeft(_Text, screen.X);
  428. Canvas.SetTop(_Text, screen.Y);
  429. JieTuWindow.AddControl(_Text);
  430. }
  431. }
  432. #endregion 添加输入框
  433. #region 拖动截图区域
  434. private void OnMove(double X, double Y)
  435. {
  436. #region X轴移动
  437. if (X > 0)
  438. {
  439. double max = AppModel.Current.MaskRightWidth > Limit.Left - AppModel.Current.MaskLeftWidth ? Limit.Left - AppModel.Current.MaskLeftWidth : AppModel.Current.MaskRightWidth;
  440. if (X > max)
  441. {
  442. X = max;
  443. }
  444. }
  445. else
  446. {
  447. double max = AppModel.Current.MaskLeftWidth > AppModel.Current.MaskLeftWidth + Width - Limit.Right ? AppModel.Current.MaskLeftWidth + Width - Limit.Right : AppModel.Current.MaskLeftWidth;
  448. if (-X > max)
  449. {
  450. X = -max;
  451. }
  452. }
  453. if (X != 0)
  454. {
  455. AppModel.Current.MaskLeftWidth += X;
  456. AppModel.Current.MaskRightWidth -= X;
  457. Canvas.SetLeft(this, Canvas.GetLeft(this) + X);
  458. }
  459. #endregion X轴移动
  460. #region Y轴移动
  461. if (Y > 0)
  462. {
  463. double max = AppModel.Current.MaskBottomHeight > Limit.Top - AppModel.Current.MaskTopHeight ? Limit.Top - AppModel.Current.MaskTopHeight : AppModel.Current.MaskBottomHeight;
  464. if (Y > max)
  465. {
  466. Y = max;
  467. }
  468. }
  469. else
  470. {
  471. double max = AppModel.Current.MaskTopHeight > AppModel.Current.MaskTopHeight + Height - Limit.Bottom ? AppModel.Current.MaskTopHeight + Height - Limit.Bottom : AppModel.Current.MaskTopHeight;
  472. if (-Y > max)
  473. {
  474. Y = -max;
  475. }
  476. }
  477. if (Y != 0)
  478. {
  479. AppModel.Current.MaskTopHeight += Y;
  480. AppModel.Current.MaskBottomHeight -= Y;
  481. Canvas.SetTop(this, Canvas.GetTop(this) + Y);
  482. }
  483. #endregion Y轴移动
  484. }
  485. #endregion 拖动截图区域
  486. #region 左缩放
  487. private void Left(double X)
  488. {
  489. if (X > 0)
  490. {
  491. double max = JieTuWindow.Current.list.Count == 0 ? Width - JieTuWindow.MinSize
  492. : Limit.Left - AppModel.Current.MaskLeftWidth < Width - JieTuWindow.MinSize ? Limit.Left - AppModel.Current.MaskLeftWidth
  493. : Width - JieTuWindow.MinSize;
  494. if (X > max)
  495. {
  496. X = max;
  497. }
  498. }
  499. else
  500. {
  501. double max = AppModel.Current.MaskLeftWidth;
  502. if (-X > max)
  503. {
  504. X = -max;
  505. }
  506. }
  507. if (X != 0)
  508. {
  509. Width -= X;
  510. Canvas.SetLeft(this, Canvas.GetLeft(this) + X);
  511. AppModel.Current.MaskLeftWidth += X;
  512. AppModel.Current.MaskTopWidth -= X;
  513. }
  514. }
  515. #endregion 左缩放
  516. #region 右缩放
  517. private void Right(double X)
  518. {
  519. if (X > 0)
  520. {
  521. double max = AppModel.Current.MaskRightWidth;
  522. if (X > max)
  523. {
  524. X = max;
  525. }
  526. }
  527. else
  528. {
  529. double max = JieTuWindow.Current.list.Count == 0 ? Width - JieTuWindow.MinSize
  530. : AppModel.Current.MaskLeftWidth + Width - Limit.Right < Width - JieTuWindow.MinSize ? AppModel.Current.MaskLeftWidth + Width - Limit.Right
  531. : Width - JieTuWindow.MinSize;
  532. if (-X > max)
  533. {
  534. X = -max;
  535. }
  536. }
  537. if (X != 0)
  538. {
  539. Width += X;
  540. AppModel.Current.MaskRightWidth -= X;
  541. AppModel.Current.MaskTopWidth += X;
  542. }
  543. }
  544. #endregion 右缩放
  545. #region 上缩放
  546. private void Top(double Y)
  547. {
  548. if (Y > 0)
  549. {
  550. double max = JieTuWindow.Current.list.Count == 0 ? Height - JieTuWindow.MinSize
  551. : Limit.Top - AppModel.Current.MaskTopHeight < Height - JieTuWindow.MinSize ? Limit.Top - AppModel.Current.MaskTopHeight
  552. : Height - JieTuWindow.MinSize;
  553. if (Y > max)
  554. {
  555. Y = max;
  556. }
  557. }
  558. else
  559. {
  560. double max = AppModel.Current.MaskLeftWidth;
  561. if (-Y > max)
  562. {
  563. Y = -max;
  564. }
  565. }
  566. if (Y != 0)
  567. {
  568. Height -= Y;
  569. Canvas.SetTop(this, Canvas.GetTop(this) + Y);
  570. AppModel.Current.MaskTopHeight += Y;
  571. }
  572. }
  573. #endregion 上缩放
  574. #region 下缩放
  575. private void Bottom(double Y)
  576. {
  577. if (Y > 0)
  578. {
  579. double max = AppModel.Current.MaskBottomHeight;
  580. if (Y > max)
  581. {
  582. Y = max;
  583. }
  584. }
  585. else
  586. {
  587. double max = JieTuWindow.Current.list.Count == 0 ? Height - JieTuWindow.MinSize
  588. : AppModel.Current.MaskTopHeight + Height - Limit.Bottom < Height - JieTuWindow.MinSize ? AppModel.Current.MaskTopHeight + Height - Limit.Bottom
  589. : Height - JieTuWindow.MinSize;
  590. if (-Y > max)
  591. {
  592. Y = -max;
  593. }
  594. }
  595. if (Y != 0)
  596. {
  597. Height += Y;
  598. AppModel.Current.MaskBottomHeight -= Y;
  599. }
  600. }
  601. #endregion 下缩放
  602. #region 刷新RGB
  603. private void OnMove(object sender, MouseEventArgs e)
  604. {
  605. Point point = PointToScreen(e.GetPosition(this));
  606. AppModel.Current.ShowRGB = ImageHelper.GetRGB((int)point.X, (int)point.Y);
  607. }
  608. #endregion 刷新RGB
  609. #region 计算图片移动的极限值
  610. public void ResetLimit(double left, double top, double right, double bottom)
  611. {
  612. ResetLeft(left);
  613. ResetTop(top);
  614. ResetRight(right);
  615. ResetButtom(bottom);
  616. }
  617. private void ResetLeft(double value)
  618. {
  619. if (value < Limit.Left)
  620. {
  621. Limit.Left = value;
  622. }
  623. }
  624. private void ResetTop(double value)
  625. {
  626. if (value < Limit.Top)
  627. {
  628. Limit.Top = value;
  629. }
  630. }
  631. private void ResetRight(double value)
  632. {
  633. if (value > Limit.Right)
  634. {
  635. Limit.Right = value;
  636. }
  637. }
  638. private void ResetButtom(double value)
  639. {
  640. if (value > Limit.Bottom)
  641. {
  642. Limit.Bottom = value;
  643. }
  644. }
  645. #endregion 计算图片移动的极限值
  646. }
  647. }