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

[Windows] Allow setting PlatformCanvas.Antialias #23965

Conversation

MartyIX
Copy link
Contributor

@MartyIX MartyIX commented Aug 1, 2024

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, tj-devel709 and mattleibow and removed request for tj-devel709 August 1, 2024 13:43
@jonathanpeppers
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@mattleibow mattleibow merged commit 363b626 into dotnet:main Aug 11, 2024
97 checks passed
@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