Skip to content

[Windows] Allow setting PlatformCanvas.Antialias#23965

Merged
mattleibow merged 1 commit into
dotnet:mainfrom
MartyIX:feature/2024-08-01-Windows-PlatformCanvas-Antialiasing
Aug 11, 2024
Merged

[Windows] Allow setting PlatformCanvas.Antialias#23965
mattleibow merged 1 commit into
dotnet:mainfrom
MartyIX:feature/2024-08-01-Windows-PlatformCanvas-Antialiasing

Conversation

@MartyIX

@MartyIX MartyIX commented Aug 1, 2024

Copy link
Copy Markdown
Contributor

Description of Change

The documentation seems to be here: https://microsoft.github.io/Win2D/WinUI3/html/P_Microsoft_Graphics_Canvas_CanvasDrawingSession_Antialiasing.htm

Observations: Antialising seems to be on by default.

Tests

My testing code

public void Draw(ICanvas canvas, RectF dirtyRect)
{
#if WINDOWS
    var platformCanvas = (Microsoft.Maui.Graphics.Win2D.W2DCanvas)canvas;
    platformCanvas.Session.Antialiasing = Microsoft.Graphics.Canvas.CanvasAntialiasing.Aliased; // EITHER THIS
    // platformCanvas.Session.Antialiasing = Microsoft.Graphics.Canvas.CanvasAntialiasing.Antialiased; // ... OR THIS
#endif

    // Left border line.
    canvas.StrokeColor = this.BorderColorLeft;
    canvas.StrokeSize = (float)this.BorderWidth.Left;
    canvas.DrawLine(0, 0, 0, dirtyRect.Height);

    // Top border line.
    canvas.StrokeColor = this.BorderColorTop;
    canvas.StrokeSize = (float)this.BorderWidth.Top;
    canvas.DrawLine(0, 0, dirtyRect.Width, 0);

    // Right border line.
    canvas.StrokeColor = this.BorderColorRight;
    canvas.StrokeSize = (float)this.BorderWidth.Right;
    canvas.DrawLine(dirtyRect.Width, 0, dirtyRect.Width, dirtyRect.Height);

    // Bottom border line.
    canvas.StrokeColor = this.BorderColorBottom;
    canvas.StrokeSize = (float)this.BorderWidth.Bottom;
    canvas.DrawLine(0, dirtyRect.Height, dirtyRect.Width, dirtyRect.Height);
}

Results:

  • With antialising ON (CanvasAntialiasing.Antialiased):
    image

  • With antialising OFF (CanvasAntialiasing.Aliased):
    image

So it appears the PR works.

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Aug 1, 2024
@MartyIX MartyIX marked this pull request as ready for review August 1, 2024 13:43
@MartyIX MartyIX requested a review from a team as a code owner August 1, 2024 13:43
@MartyIX MartyIX requested review from PureWeen, mattleibow and tj-devel709 and removed request for tj-devel709 August 1, 2024 13:43
@jonathanpeppers

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@mattleibow mattleibow merged commit 363b626 into dotnet:main Aug 11, 2024
@samhouts samhouts added the fixed-in-net8.0-nightly This may be available in a nightly release! label Aug 12, 2024
@samhouts samhouts added the fixed-in-net9.0-nightly This may be available in a nightly release! label Aug 27, 2024
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution fixed-in-net8.0-nightly This may be available in a nightly release! fixed-in-net9.0-nightly This may be available in a nightly release!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants