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

Question: How to Disable Anti-Aliasing When Drawing Images on CanvasVirtualControl for Sharp Pixel Display? #965

Open
bj-gegf opened this issue Oct 11, 2024 · 2 comments

Comments

@bj-gegf
Copy link

bj-gegf commented Oct 11, 2024

I'm developing a graphic processing tool that needs to display images with zoom functionality. My goal is to ensure that when an image is enlarged, the pixels are clearly visible, similar to Windows Paint, rather than appearing blurry due to anti-aliasing.

I tried this using the Win2D-Samples VirtualBitmapExample by placing a CanvasVirtualControl in a ScrollView and utilizing the DrawImage method of the CanvasDrawingSession to render the image. However, the result is still a blurry image.

Any advice on how to achieve sharp pixel display without anti-aliasing would be greatly appreciated!

private void ImageVirtualControl_RegionsInvalidated(CanvasVirtualControl sender, CanvasRegionsInvalidatedEventArgs args)
{
    foreach (var region in args.InvalidatedRegions)
    {
        using (var ds = ImageVirtualControl.CreateDrawingSession(region))
        {
            if (virtualBitmap != null)
            {
                ds.Units = CanvasUnits.Pixels;
                ds.Antialiasing = CanvasAntialiasing.Aliased;                
                ds.DrawImage(virtualBitmap, region, region, 1, CanvasImageInterpolation.NearestNeighbor);
            }
        }
    }
}

Expect Result:
Image

Actual Result:
Image

@getrou
Copy link
Member

getrou commented Oct 14, 2024

Hm, good question! I haven't had time to investigate yet, but I have some ideas. CanvasControl and CanvasVirtualControl are offscreen render targets, so the NearestNeighbor that you are using here is just for rendering your image to your off-screen render target. That then gets scaled up in the ScrollView, so now you need to tell either the ScrollViewer or the CanvasVirtualControl how to filter when drawing that scaled up render target to the screen.

@bj-gegf
Copy link
Author

bj-gegf commented Oct 16, 2024

@getrou thank you for response.
I think in WPF we can set RenderOptions.BitmapScalingMode to resovle the issue, but cannot found similar options in WinUI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants