Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uncatched Exception on finger painting fix #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions src/BitooBitImageEditor/Helper/SKCanvasExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Linq;

namespace BitooBitImageEditor.Helper
{
Expand All @@ -12,8 +13,9 @@ internal static void DrawBitmap(this SKCanvas canvas, List<TouchManipulationBitm
using (SKPaint paint = new SKPaint())
{
paint.IsAntialias = true;
List<TouchManipulationBitmap> cloneList = new List<TouchManipulationBitmap>(bitmapCollection.Where(e => e != null).ToList());

foreach (var item in bitmapCollection)
foreach (var item in cloneList)
canvas.DrawBitmap(item, transX, transY, scale);
}
}
Expand All @@ -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())
Expand All @@ -62,7 +61,7 @@ internal static void DrawBackground(this SKCanvas canvas, SKBitmap bitmap, SKRec
}


internal static void DrawPath(this SKCanvas canvas, List<PaintedPath> completedPaths, Dictionary<long, PaintedPath> inProgressPaths)
internal static void DrawPath(this SKCanvas canvas, List<PaintedPath> completedPaths, List<PaintedPath> inProgressPaths)
{
using (SKPaint paint = new SKPaint())
{
Expand All @@ -72,20 +71,31 @@ internal static void DrawPath(this SKCanvas canvas, List<PaintedPath> completedP
paint.StrokeJoin = SKStrokeJoin.Round;
paint.IsAntialias = true;


if(completedPaths != null)
foreach (PaintedPath path in completedPaths)
if (completedPaths != null)
{
List<PaintedPath> cloneList = new List<PaintedPath>(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<PaintedPath> cloneList = new List<PaintedPath>(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);
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down