CommunityToolkit / CommunityToolkit/Windows

ImageCropper is not able to work with BitmapImage.

Open
#617 0 comments 0 reactions 0 assignees View on GitHub
bug components::controls::imagecropper
Dominant language
C#
Stars
1.1k
Forks
166
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

Trying to work with `ImageCropper` to generate a cropping region, I am forced to use `WriteableBitmap`.
While I understand that some parts of the components will want to work with a `WriteableBitmap`, but that is not the case for the core UI function of selecting a cropping zone.
This prevents for example, one from using `BitmapImages` which support animated images.
It should be perfectly reasonable to allow users to use the component only for its UI presentation features, and implement the cropping themselves if they desire to.

### Steps to reproduce

```text
Try loading an animated image into the ImageCropper. It will only show the first frame.
Setting a BitmapImage loaded externally as the source is not possible.
```

### Expected behavior

`ImageCropper` should accept any `BitmapSource` as an input (as it contains the properties `PixelWidth` and `PixelHeight` that are used everywhere).
`ImageCropper` should throw an exception if methods that require the `Source` to be a `WriteableBitmap` are called when the `Source` is of a different type.

### Screenshots

_No response_

### Code Platform

- [ ] UWP
- [x] WinAppSDK / WinUI 3
- [ ] Web Assembly (WASM)
- [ ] Android
- [ ] iOS
- [ ] MacOS
- [ ] Linux / GTK

### Windows Build Number

- [ ] Windows 10 1809 (Build 17763)
- [ ] Windows 10 1903 (Build 18362)
- [ ] Windows 10 1909 (Build 18363)
- [ ] Windows 10 2004 (Build 19041)
- [ ] Windows 10 20H2 (Build 19042)
- [ ] Windows 10 21H1 (Build 19043)
- [ ] Windows 10 21H2 (Build 19044)
- [ ] Windows 10 22H2 (Build 19045)
- [ ] Windows 11 21H2 (Build 22000)
- [ ] Other (specify)

### Other Windows Build number

_No response_

### App minimum and target SDK version

- [ ] Windows 10, version 1809 (Build 17763)
- [ ] Windows 10, version 1903 (Build 18362)
- [ ] Windows 10, version 1909 (Build 18363)
- [ ] Windows 10, version 2004 (Build 19041)
- [ ] Windows 10, version 2104 (Build 20348)
- [ ] Windows 11, version 22H2 (Build 22000)
- [x] Other (specify)

### Other SDK version

10.0.22621.48

### Visual Studio Version

2022

### Visual Studio Build Number

_No response_

### Device form factor

Desktop

### Additional context

AFAIK, the only part that actually requires the source to be a `WriteableBitmap` is https://github.com/CommunityToolkit/Windows/blob/main/components/ImageCropper/src/ImageCropper.Helpers.cs

The `ImageCropper` should accept images that are loaded asynchronously, as a `BitmapSource` is not guaranteed to have dimensions until the image is actually loaded. It is already a problem on the current implementation using WriteableBitmap. (If one is creating a 1x1 bitmap before asynchronously loading the image, `ImageCropper` will reject it)
This can be addressed by listening for changes to `PixelWidth` and `PixelHeight` properties instead of rejecting the Source. (using [RegisterPropertyChangedCallback ](https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.dependencyobject.registerpropertychangedcallback?view=winrt-26100#windows-ui-xaml-dependencyobject-registerpropertychangedcallback(windows-ui-xaml-dependencyproperty-windows-ui-xaml-dependencypropertychangedcallback))
In case any of those properties are not valid, it should be possible for the `ImageCropper` to simply consider the image as not being assigned, which will make it work more gracefully in different scenarios.

### Help us help you

Yes, I'd like to be assigned to work on this item.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.