private void DrawToSession([CanBeNull] CanvasDrawingSession g, DPoint[] strokeToRender, [NotNull] Quad clipRegion, double zoom, bool dim = false) { try { var pts = strokeToRender; if (pts == null || pts.Length < 1) { return; } // using the ink infrastructure for drawing... var strokes = new List <InkStroke>(); var attr = GetPenAttributes(zoom, pts); if (dim) { attr.Color = Color.FromArgb(255, 127, 127, 127); } var s = new CoreIncrementalInkStroke(attr, Matrix3x2.Identity); for (int i = 0; i < pts.Length; i++) { var current = pts[i]; s.AppendInkPoints(new[] { new InkPoint(new Point((current.X - clipRegion.X) * zoom, (current.Y - clipRegion.Y) * zoom), (float)current.Pressure) }); } var stroke = s.CreateInkStroke(); if (stroke == null) { throw new Exception("Stroke creation failed"); } strokes.Add(stroke); g?.DrawInk(strokes); // this call can be *very* slow! It's bad when using wide strokes at high zoom levels. } catch (Exception ex) { Logging.WriteLogMessage(ex.ToString()); } }
private async Task <StorageFile> ExportCanvasAndImageAsync(StorageFile imageFile) { var saveFile = await GetImageToSaveAsync(); if (saveFile == null) { return(null); } // Prevent updates to the file until updates are finalized with call to CompleteUpdatesAsync. CachedFileManager.DeferUpdates(saveFile); using (var outStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite)) { var device = CanvasDevice.GetSharedDevice(); CanvasBitmap canvasbitmap; using (var stream = await imageFile.OpenAsync(FileAccessMode.Read)) { canvasbitmap = await CanvasBitmap.LoadAsync(device, stream); } using (var renderTarget = new CanvasRenderTarget(device, (int)_inkCanvas.Width, (int)_inkCanvas.Height, canvasbitmap.Dpi)) { using (CanvasDrawingSession ds = renderTarget.CreateDrawingSession()) { ds.DrawImage(canvasbitmap, new Rect(0, 0, (int)_inkCanvas.Width, (int)_inkCanvas.Height)); ds.DrawInk(_strokesService.GetStrokes()); } await renderTarget.SaveAsync(outStream, CanvasBitmapFileFormat.Png); } } // Finalize write so other apps can update file. FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(saveFile); return(saveFile); }
public void Render(CanvasDrawingSession session, IEnumerable <InkStroke> strokes) { session.Clear(Colors.White); session.DrawInk(strokes, false); }
private void DrawStrokesToInkSurface(CanvasDrawingSession ds, IList <InkStroke> strokes) { ds.DrawInk(strokes); }
public void Render(CanvasDrawingSession drawingSession, Matrix3x2 displayTransform, bool isHighContrast) { SetDisplayTransform(displayTransform); drawingSession.DrawInk(new InkStroke[] { Stroke }, isHighContrast); }