星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PracticeWindow.xaml.cs 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  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.Ink;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. namespace XHWK.WKTool
  17. {
  18. /// <summary>
  19. /// 录屏画板
  20. /// </summary>
  21. public partial class PracticeWindow : Window
  22. {
  23. //声明一个 DrawingAttributes 类型的变量
  24. DrawingAttributes drawingAttributes;
  25. public PracticeWindow()
  26. {
  27. InitializeComponent();
  28. }
  29. public void Initialize(string _imgPath)
  30. {
  31. blackboard_canvas.Strokes.Clear();
  32. blackboard_canvas.UseCustomCursor = true;
  33. //blackboard_canvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
  34. if (File.Exists(_imgPath))
  35. {
  36. imgCanvas.Source = new BitmapImage(new Uri(_imgPath));
  37. }
  38. //创建 DrawingAttributes 类的一个实例
  39. drawingAttributes = new DrawingAttributes();
  40. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  41. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  42. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  43. Pen();
  44. blackboard_canvas.Cursor = Cursors.Pen;
  45. //Cursor cus = new Cursor(@"G:\Icon.ico");
  46. //blackboard_canvas.Cursor = cus;
  47. }
  48. /// <summary>
  49. /// 画笔颜色事件 白色
  50. /// </summary>
  51. /// <param name="sender"></param>
  52. /// <param name="e"></param>
  53. public void White()
  54. {
  55. drawingAttributes.Color = Colors.White;
  56. }
  57. /// <summary>
  58. /// 画笔颜色事件 红色
  59. /// </summary>
  60. /// <param name="sender"></param>
  61. /// <param name="e"></param>
  62. public void Red()
  63. {
  64. //设置 DrawingAttributes 的 Color 属性设置颜色
  65. drawingAttributes.Color = Colors.Red;
  66. }
  67. /// <summary>
  68. /// 画笔颜色事件 灰色
  69. /// </summary>
  70. /// <param name="sender"></param>
  71. /// <param name="e"></param>
  72. public void Gray()
  73. {
  74. drawingAttributes.Color = Colors.Gray;
  75. }
  76. /// <summary>
  77. /// 画笔颜色事件 青色
  78. /// </summary>
  79. /// <param name="sender"></param>
  80. /// <param name="e"></param>
  81. public void CyanBlue()
  82. {
  83. drawingAttributes.Color = Colors.LimeGreen;
  84. }
  85. /// <summary>
  86. /// 画笔颜色事件 黄色
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. public void Yellow()
  91. {
  92. drawingAttributes.Color = Colors.Gold;
  93. }
  94. /// <summary>
  95. /// 画笔颜色事件 蓝色
  96. /// </summary>
  97. /// <param name="sender"></param>
  98. /// <param name="e"></param>
  99. public void Blue()
  100. {
  101. drawingAttributes.Color = Colors.DeepSkyBlue;
  102. }
  103. /// <summary>
  104. /// 画笔粗细事件 细
  105. /// </summary>
  106. /// <param name="sender"></param>
  107. /// <param name="e"></param>
  108. public void Fine()
  109. {
  110. drawingAttributes.Width = 1;
  111. drawingAttributes.Height = 1;
  112. }
  113. /// <summary>
  114. /// 画笔粗细事件 中
  115. /// </summary>
  116. /// <param name="sender"></param>
  117. /// <param name="e"></param>
  118. public void In()
  119. {
  120. drawingAttributes.Width = 3;
  121. drawingAttributes.Height = 3;
  122. }
  123. /// <summary>
  124. /// 画笔粗细事件 粗
  125. /// </summary>
  126. /// <param name="sender"></param>
  127. /// <param name="e"></param>
  128. public void Crude()
  129. {
  130. drawingAttributes.Width = 5;
  131. drawingAttributes.Height = 5;
  132. }
  133. public void Eraser()
  134. {
  135. //this.type = ZPenType.Erase;
  136. blackboard_canvas.UseCustomCursor = false;
  137. blackboard_canvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
  138. blackboard_canvas.EraserShape = new EllipseStylusShape(64, 64, 0);
  139. }
  140. public void Pen()
  141. {
  142. blackboard_canvas.EditingMode = InkCanvasEditingMode.Ink;
  143. blackboard_canvas.UseCustomCursor = true;
  144. drawingAttributes.FitToCurve = true;
  145. drawingAttributes.IgnorePressure = false;
  146. blackboard_canvas.Cursor = Cursors.Pen;
  147. }
  148. }
  149. }