using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace XHWK.WKTool { /// /// 录屏画板 /// public partial class PracticeWindow : Window { //声明一个 DrawingAttributes 类型的变量 DrawingAttributes drawingAttributes; public PracticeWindow() { InitializeComponent(); } public void Initialize(string _imgPath) { blackboard_canvas.Strokes.Clear(); blackboard_canvas.UseCustomCursor = true; //blackboard_canvas.EditingMode = InkCanvasEditingMode.EraseByStroke; if (File.Exists(_imgPath)) { imgCanvas.Source = new BitmapImage(new Uri(_imgPath)); } //创建 DrawingAttributes 类的一个实例 drawingAttributes = new DrawingAttributes(); //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用 //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型 blackboard_canvas.DefaultDrawingAttributes = drawingAttributes; Pen(); blackboard_canvas.Cursor = Cursors.Pen; //Cursor cus = new Cursor(@"G:\Icon.ico"); //blackboard_canvas.Cursor = cus; } /// /// 画笔颜色事件 白色 /// /// /// public void White() { drawingAttributes.Color = Colors.White; } /// /// 画笔颜色事件 红色 /// /// /// public void Red() { //设置 DrawingAttributes 的 Color 属性设置颜色 drawingAttributes.Color = Colors.Red; } /// /// 画笔颜色事件 灰色 /// /// /// public void Gray() { drawingAttributes.Color = Colors.Gray; } /// /// 画笔颜色事件 青色 /// /// /// public void CyanBlue() { drawingAttributes.Color = Colors.LimeGreen; } /// /// 画笔颜色事件 黄色 /// /// /// public void Yellow() { drawingAttributes.Color = Colors.Gold; } /// /// 画笔颜色事件 蓝色 /// /// /// public void Blue() { drawingAttributes.Color = Colors.DeepSkyBlue; } /// /// 画笔粗细事件 细 /// /// /// public void Fine() { drawingAttributes.Width = 1; drawingAttributes.Height = 1; } /// /// 画笔粗细事件 中 /// /// /// public void In() { drawingAttributes.Width = 3; drawingAttributes.Height = 3; } /// /// 画笔粗细事件 粗 /// /// /// public void Crude() { drawingAttributes.Width = 5; drawingAttributes.Height = 5; } public void Eraser() { //this.type = ZPenType.Erase; blackboard_canvas.UseCustomCursor = false; blackboard_canvas.EditingMode = InkCanvasEditingMode.EraseByPoint; blackboard_canvas.EraserShape = new EllipseStylusShape(64, 64, 0); } public void Pen() { blackboard_canvas.EditingMode = InkCanvasEditingMode.Ink; blackboard_canvas.UseCustomCursor = true; drawingAttributes.FitToCurve = true; drawingAttributes.IgnorePressure = false; blackboard_canvas.Cursor = Cursors.Pen; } } }