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

Made clear behavior in RenderTargetBitmap.CreateDrawingContext optional #12793

Merged
merged 9 commits into from
Sep 10, 2023
16 changes: 15 additions & 1 deletion src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,24 @@ private static IRenderTargetBitmapImpl CreateImpl(PixelSize size, Vector dpi)
return factory.CreateRenderTargetBitmap(size, dpi);
}

/// <summary>
/// Creates a <see cref="DrawingContext"/> for drawing to the <see cref="RenderTargetBitmap"/>.
/// Clears the current image data to transparent.
/// </summary>
/// <returns>The drawing context.</returns>
public DrawingContext CreateDrawingContext()
=> CreateDrawingContext(true);

/// <summary>
/// Creates a <see cref="DrawingContext"/> for drawing to the <see cref="RenderTargetBitmap"/>.
/// </summary>
/// <param name="clear">If true, clears the current image data to transparent, if false, leaves the image data unchanged.</param>
/// <returns>The drawing context.</returns>
public DrawingContext CreateDrawingContext(bool clear)
{
var platform = PlatformImpl.Item.CreateDrawingContext();
platform.Clear(Colors.Transparent);
if(clear)
platform.Clear(Colors.Transparent);
return new PlatformDrawingContext(platform);
}

Expand Down