public override Boolean OnTouchDown(Int32 touchId, Point point) { this.TouchId = touchId; if (points.Count == 0) { this.drawingCanvas.AddWorkingDrawTool(this); this.pen = this.drawingCanvas.Pen; this.fontSize = this.drawingCanvas.FontSize; this.typeface = new Typeface(new FontFamily("Microsoft YaHei UI,Tahoma"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); this.dpi = DpiHelper.GetDpiFromVisual(this.drawingCanvas); points.Add(point); geometry = new PathGeometry(); var figure = new PathFigure { StartPoint = point }; pathGeometry.Figures.Add(figure); this.CanTouchMove = true; if (this.TouchId != 0 || !this.drawingCanvas.CaptureMouse()) { this.CanTouchLeave = true; } this.drawingCanvas.AddVisual(this); } else if ((point - points.Last()).Length <= pen.Thickness) { return(OnTouchLeave(point)); } else if (mousePoint.HasValue) { points.Add(mousePoint.Value); mousePoint = null; } return(true); }
private void OnSaveImageClick(Object sender, RoutedEventArgs e) { var backgroundImage = this.drawViewer.BackgroundImage; var frame = this.drawCanvas.ToBitmapFrame(backgroundImage.PixelWidth, backgroundImage.PixelHeight, DpiHelper.GetDpiFromVisual(this.drawCanvas), backgroundImage); if (frame == null) { return; } var folder = Path.Combine(Environment.CurrentDirectory, "Images"); if (!Directory.Exists(folder)) { Directory.CreateDirectory("Images"); } var dlg = new SaveFileDialog { Filter = "Images files (*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp", OverwritePrompt = true, DefaultExt = "jpg", InitialDirectory = folder, RestoreDirectory = true }; if ((Boolean)dlg.ShowDialog()) { ImageHelper.Save(dlg.FileName, frame); } }
private void OnPrintClick(Object sender, RoutedEventArgs e) { var backgroundImage = this.drawViewer.BackgroundImage; this.drawCanvas.Print(backgroundImage.PixelWidth, backgroundImage.PixelHeight, DpiHelper.GetDpiFromVisual(this.drawCanvas), backgroundImage); }