Skip to content

[BUG] DrawingViewService.GetImageStream does not resize image stream correctly in WinUI #2570

Closed

Description

@ngieske-MSI

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

When calling DrawingViewService.GetImageStream with ImageLineOptions.FullCanvas method, the documentation states that the resulting image will be resized proportionally according to the desiredSize parameter. Though it doesn't specifically explain how that resizing will happen, from my tests it appears that it will take the width and height of the image and scale them one-for-one until one of them reaches the corresponding limit set in the desiredSize parameter. This behavior is expected and works fine in Android and iOS.

However, a problem arises in the WinUI platform. In Windows, it appears that the desiredSize parameter is ignored entirely and the resulting image size is determined entirely by the canvasSize parameter. This presents two problems: One, the image is not resized at all and therefore the scale of the resulting image is inaccurate, and two, the resulting image relies on the bounds of the DrawingView control to determine how big it should become, which leads to different image sizes on different devices.

As an example:
Lets say for all platforms, we have a DrawingView control that has a width of 300 and a height of 400. We set the desiredImageSize to a width and height of (2000, 2000). On Android and iOS, the resulting image after calling DrawingViewService.GetImageStream with ImageLineOptions.FullCanvas filled in will be (1500,2000) because the height limit is reached before the width limit while scaling the line drawing up to the desired size. However, on Windows, the resulting image will remain a size of (300,400) because Windows does not take the desiredImageSize into account and just spits out exactly what the user drew, in the resolution they drew it in.

Expected Behavior

Using the ImageLineOptions.FullCanvas method to scale the DrawingView's line image via the desiredSize parameter should have equivalent behaviors on all platforms. Specifically, Windows should behave in a manner identical or at least similar to Android and iOS.

Steps To Reproduce

  1. Open and run the solution from the reproduction repository.
  2. Draw any lines you see fit within the DrawingView control, then press the save button.
  3. View the image in an external image viewer and take note of the image's width and height.

On Android and iOS, the output image's width and/or height will have a maximum value as defined by the desiredImageSize object. This is (presumably) the expected behavior. On Windows, the output image's width and height are determined entirely by the size of the _drawView control within the application, which theoretically could be different depending on the device used.

Link to public reproduction project repository

https://github.com/ngieske-MSI/DrawingViewBehaviorComparison

Environment

- .NET MAUI CommunityToolkit: 11.1.0
- OS: Tested on: 
  - Android 14 (API level 34)
  - iOS 17.6.1 on both iPhone and iPad
  - Windows 11 Version 10.0.26100 Build 26100
- .NET MAUI: 9.0.40

Anything else?

The DrawingView image resizing functionality has been the topic of some discussion in previous bugs; see #1397

The latest update to the CommunityToolkit included a PR that added the most recent resizing functionality: #2193

Activity

  1. bijington commented on Mar 6, 2025

    @bijington
    Contributor

    Thank you for the report. I can check to see what I missed on Windows.

    As for the documentation it should state that it maintains the aspect ratio of the drawn image which I can include. I've currently taken the assumption this would be the expected behaviour until someone has a need to not preserve the aspect ratio.

  2. ngieske-MSI commented on Jun 4, 2025

    @ngieske-MSI
    Author

    Is there any update on this? I have tried to work around the issue by manually scaling the DrawingView's LineCollection based on a scale factor calculated from the DrawingView control's size vs. the desired image size, but for whatever reason the result is still not upscaled correctly. Having a fix from the toolkit itself would be a great relief.

  3. bijington commented on Jun 5, 2025

    @bijington
    Contributor

    Not yet. I'll try and take a look at this soon though

  4. locked and limited conversation to collaborators on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions