From 867dbeacdaa4a298ee7fe5f2ade4317e73bc21ac Mon Sep 17 00:00:00 2001 From: PMahern Date: Tue, 5 Sep 2023 15:58:30 -0500 Subject: [PATCH 1/4] Made clear behavior in RenderTargetBitmap.CreateDrawingContext optional The original behavior is still preserved so this shouldn't be a breaking change for anyone relying on the clear behavior. --- src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs b/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs index d638630bb1..5824a2b994 100644 --- a/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs +++ b/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs @@ -62,10 +62,16 @@ namespace Avalonia.Media.Imaging return factory.CreateRenderTargetBitmap(size, dpi); } - public DrawingContext CreateDrawingContext() + /// + /// Creates a for drawing to the . + /// + /// Indicates if the image should be cleared. + /// The drawing context. + public DrawingContext CreateDrawingContext(bool clear = true) { var platform = PlatformImpl.Item.CreateDrawingContext(); - platform.Clear(Colors.Transparent); + if(clear) + platform.Clear(Colors.Transparent); return new PlatformDrawingContext(platform); } From 29c84b13ab81f38f71da5e800447e0fe8bcfa8f8 Mon Sep 17 00:00:00 2001 From: Paisley Date: Wed, 6 Sep 2023 12:51:15 -0500 Subject: [PATCH 2/4] Added updated Avalonia.nupkg.xml --- api/Avalonia.nupkg.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/Avalonia.nupkg.xml b/api/Avalonia.nupkg.xml index 6a7d53544e..3c1071e1ef 100644 --- a/api/Avalonia.nupkg.xml +++ b/api/Avalonia.nupkg.xml @@ -1,6 +1,12 @@  + + CP0002 + M:Avalonia.Media.Imaging.RenderTargetBitmap.CreateDrawingContext + baseline/netstandard2.0/Avalonia.Base.dll + target/netstandard2.0/Avalonia.Base.dll + CP0006 P:Avalonia.Rendering.Composition.ICompositionGpuImportedObject.ImportCompleted From 9e94055bc126e63090e0fb887b664845293f3daa Mon Sep 17 00:00:00 2001 From: Paisley Date: Fri, 8 Sep 2023 11:20:51 -0500 Subject: [PATCH 3/4] Added a function to RenderTargetBitmap to create a DrawingContext for editing the current image data and not clearing it. --- api/Avalonia.nupkg.xml | 6 ------ .../Media/Imaging/RenderTargetBitmap.cs | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/api/Avalonia.nupkg.xml b/api/Avalonia.nupkg.xml index 3c1071e1ef..6a7d53544e 100644 --- a/api/Avalonia.nupkg.xml +++ b/api/Avalonia.nupkg.xml @@ -1,12 +1,6 @@  - - CP0002 - M:Avalonia.Media.Imaging.RenderTargetBitmap.CreateDrawingContext - baseline/netstandard2.0/Avalonia.Base.dll - target/netstandard2.0/Avalonia.Base.dll - CP0006 P:Avalonia.Rendering.Composition.ICompositionGpuImportedObject.ImportCompleted diff --git a/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs b/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs index 5824a2b994..4adac60c2d 100644 --- a/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs +++ b/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs @@ -63,15 +63,24 @@ namespace Avalonia.Media.Imaging } /// - /// Creates a for drawing to the . + /// Creates a for drawing to the . + /// Clears the current image data to transparent. /// - /// Indicates if the image should be cleared. /// The drawing context. - public DrawingContext CreateDrawingContext(bool clear = true) + public DrawingContext CreateDrawingContext() + { + var platform = PlatformImpl.Item.CreateDrawingContext(); + platform.Clear(Colors.Transparent); + return new PlatformDrawingContext(platform); + } + + /// + /// Creates a for editing the already existing image in the . + /// + /// The drawing context. + public DrawingContext CreateEditDrawingContext() { var platform = PlatformImpl.Item.CreateDrawingContext(); - if(clear) - platform.Clear(Colors.Transparent); return new PlatformDrawingContext(platform); } From 59d14ddcea1d93f0293280b702bc6ab6fe026ee3 Mon Sep 17 00:00:00 2001 From: Paisley Mahern Date: Fri, 8 Sep 2023 14:20:02 -0500 Subject: [PATCH 4/4] Update RenderTargetBitmap.cs --- .../Media/Imaging/RenderTargetBitmap.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs b/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs index 4adac60c2d..b1c9c81b39 100644 --- a/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs +++ b/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs @@ -68,19 +68,18 @@ namespace Avalonia.Media.Imaging /// /// The drawing context. public DrawingContext CreateDrawingContext() - { - var platform = PlatformImpl.Item.CreateDrawingContext(); - platform.Clear(Colors.Transparent); - return new PlatformDrawingContext(platform); - } + => CreateDrawingContext(true); /// - /// Creates a for editing the already existing image in the . + /// Creates a for drawing to the . /// + /// If true, clears the current image data to transparent, if false, leaves the image data unchanged. /// The drawing context. - public DrawingContext CreateEditDrawingContext() + public DrawingContext CreateDrawingContext(bool clear) { var platform = PlatformImpl.Item.CreateDrawingContext(); + if(clear) + platform.Clear(Colors.Transparent); return new PlatformDrawingContext(platform); }