CommunityToolkit / CommunityToolkit/Windows

ImageCropper is not able to work with BitmapImage.

Aperta
#617 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug components::controls::imagecropper
Lingua principale
C#
Stelle
1.1k
Fork
166
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia dalla gestione delle sorgenti di ImageCropper e da components/ImageCropper/src/ImageCropper.Helpers.cs, che l’issue identifica come la parte che richiede WriteableBitmap. Traccia come vengono validate le dimensioni di Source e come viene gestito il caricamento asincrono. Il lavoro è completato quando gli input BitmapSource, comprese le immagini animate o non ancora dimensionate, possono pilotare l’interfaccia di selezione, mentre le operazioni che richiedono WriteableBitmap falliscono in modo chiaro quando appropriato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
desktop, frontend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.