CommunityToolkit / CommunityToolkit/Windows

ImageCropper is not able to work with BitmapImage.

Offen
#617 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug components::controls::imagecropper
Vorherrschende Sprache
C#
Sterne
1.1k
Forks
166
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit der Verarbeitung von ImageCropper-Quellen und components/ImageCropper/src/ImageCropper.Helpers.cs, die der Issue als den Teil identifiziert, der WriteableBitmap erfordert. Verfolge, wie die Dimensionen von Source validiert werden und wie das asynchrone Laden behandelt wird. Als erledigt gilt, dass BitmapSource-Eingaben, einschließlich animierter oder noch nicht dimensionierter Bilder, die Auswahl-UI steuern können, während Vorgänge, die WriteableBitmap erfordern, wenn angemessen eindeutig fehlschlagen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
desktop, frontend
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.