From e785071d55ec3f64036ac2670060c492246290bd Mon Sep 17 00:00:00 2001 From: RajneeshSingh007 Date: Fri, 19 Nov 2021 11:20:52 +0530 Subject: [PATCH] uncatched Exception on finger painting fix --- .../Helper/SKCanvasExtension.cs | 38 ++++++++++++------- .../TouchManipulationCanvasView.cs | 2 +- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/BitooBitImageEditor/Helper/SKCanvasExtension.cs b/src/BitooBitImageEditor/Helper/SKCanvasExtension.cs index 28a07f2..8bb22e9 100644 --- a/src/BitooBitImageEditor/Helper/SKCanvasExtension.cs +++ b/src/BitooBitImageEditor/Helper/SKCanvasExtension.cs @@ -2,6 +2,7 @@ using SkiaSharp; using System; using System.Collections.Generic; +using System.Linq; namespace BitooBitImageEditor.Helper { @@ -12,8 +13,9 @@ internal static void DrawBitmap(this SKCanvas canvas, List cloneList = new List(bitmapCollection.Where(e => e != null).ToList()); - foreach (var item in bitmapCollection) + foreach (var item in cloneList) canvas.DrawBitmap(item, transX, transY, scale); } } @@ -38,9 +40,6 @@ internal static void DrawBitmap(this SKCanvas canvas, TouchManipulationBitmap bi } - - - internal static void DrawBackground(this SKCanvas canvas, SKBitmap bitmap, SKRect rect, ImageEditorConfig config) { using (SKPaint paint = new SKPaint()) @@ -62,7 +61,7 @@ internal static void DrawBackground(this SKCanvas canvas, SKBitmap bitmap, SKRec } - internal static void DrawPath(this SKCanvas canvas, List completedPaths, Dictionary inProgressPaths) + internal static void DrawPath(this SKCanvas canvas, List completedPaths, List inProgressPaths) { using (SKPaint paint = new SKPaint()) { @@ -72,20 +71,31 @@ internal static void DrawPath(this SKCanvas canvas, List completedP paint.StrokeJoin = SKStrokeJoin.Round; paint.IsAntialias = true; - - if(completedPaths != null) - foreach (PaintedPath path in completedPaths) + if (completedPaths != null) + { + List cloneList = new List(completedPaths.Where(e => e != null).ToList()); + if (cloneList.Count > 0) { - paint.Color = path.Color; - canvas.DrawPath(path.Path, paint); + foreach (PaintedPath path in cloneList) + { + paint.Color = path.Color; + canvas.DrawPath(path.Path, paint); + } } + + } - if (inProgressPaths != null) - foreach (PaintedPath path in inProgressPaths?.Values) + if (inProgressPaths != null) { + List cloneList = new List(inProgressPaths.Where(e => e != null).ToList()); + if(cloneList.Count > 0) { - paint.Color = path.Color; - canvas.DrawPath(path.Path, paint); + foreach (PaintedPath path in cloneList) + { + paint.Color = path.Color; + canvas.DrawPath(path.Path, paint); + } } + } } } diff --git a/src/BitooBitImageEditor/ManipulationBitmap/TouchManipulationCanvasView.cs b/src/BitooBitImageEditor/ManipulationBitmap/TouchManipulationCanvasView.cs index 0676d4d..a8d4e73 100644 --- a/src/BitooBitImageEditor/ManipulationBitmap/TouchManipulationCanvasView.cs +++ b/src/BitooBitImageEditor/ManipulationBitmap/TouchManipulationCanvasView.cs @@ -138,7 +138,7 @@ private void OnPaintSurface(SKCanvas canvas, SKRect rect, bool isDrawResult, flo canvas.Save(); canvas.SetMatrix(new SKMatrix(scale, 0, transX * scale, 0, scale, transY * scale, 0, 0, 1)); canvas.DrawBitmap(mainBitmap, transX, transY, scale); - canvas.DrawPath(completedPaths, isDrawResult ? null : inProgressPaths); + canvas.DrawPath(completedPaths, isDrawResult ? null : inProgressPaths?.Values.ToList()); canvas.Restore(); canvas.DrawBitmap(bitmapCollection, transX, transY, scale); }