CommunityToolkit / CommunityToolkit/Maui

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

Open
#2,570 3 comments 0 reactions 0 assignees View on GitHub
bug unverified
Dominant language
C#
Stars
2.7k
Forks
500
Avg merge
2d 14h
Merged PRs (30d)
7

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

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

- [x] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug

### 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

```markdown
- .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

Contributor guide

Open the contributing guide

Research direction

Start at DrawingViewService.GetImageStream and compare the WinUI path with the Android and iOS behavior described in the issue. Use the linked DrawingViewBehaviorComparison repository to reproduce the size discrepancy, then verify that ImageLineOptions.FullCanvas respects desiredSize proportionally on Windows and produces equivalent output across platforms.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.