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

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

Open
2 tasks done
ngieske-MSI opened this issue Mar 5, 2025 · 1 comment
Open
2 tasks done
Labels
bug Something isn't working unverified

Comments

@ngieske-MSI
Copy link

ngieske-MSI commented Mar 5, 2025

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

@ngieske-MSI ngieske-MSI added bug Something isn't working unverified labels Mar 5, 2025
@bijington
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unverified
Projects
None yet
Development

No branches or pull requests

2 participants