-
Notifications
You must be signed in to change notification settings - Fork 473
Return Camera Image (Stream) from ICameraView.CaptureImage()
#2695
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
Return Camera Image (Stream) from ICameraView.CaptureImage()
#2695
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors ICameraView.CaptureImage() to return a Task<Stream> instead of ValueTask, implements a semaphore-protected event‐based capture flow, and adds disposal logic to CameraView.
- Introduces
IDisposableonCameraViewfor cleanup ofSemaphoreSlim - Changes
CaptureImagetoasync Task<Stream>, usesTaskCompletionSource<Stream>withMediaCaptured/MediaCaptureFailedevents - Updates
ICameraViewinterface signature and adjusts related bindable property defaults
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/CommunityToolkit.Maui.Camera/Views/CameraView.shared.cs | Added IDisposable, semaphore management, new CaptureImage logic |
| src/CommunityToolkit.Maui.Camera/Interfaces/ICameraView.shared.cs | Updated CaptureImage from ValueTask to Task<Stream> |
Comments suppressed due to low confidence (2)
src/CommunityToolkit.Maui.Camera/Views/CameraView.shared.cs:221
- The new
CaptureImagebehavior (success, failure, cancellation, and concurrent calls) isn’t covered by existing tests—consider adding unit or integration tests to validate event unsubscription, exception paths, and semaphore behavior.
public async Task<Stream> CaptureImage(CancellationToken token)
src/CommunityToolkit.Maui.Camera/Interfaces/ICameraView.shared.cs:58
- Update any public API docs, samples, and IntelliSense comments to reflect that
CaptureImagenow returns aTask<Stream>instead ofValueTaskand no longer relies on theMediaCapturedevent.
Task<Stream> CaptureImage(CancellationToken token);
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Description of Change
API Change
This PR updates
ICameraView.CaptureImage()to return theStreamcaptured by the camera:to
Developer Experience Improvement
This improves the developer experience, allowing devs to retrieve the image directly from the method, whereas the current/previous experience required them to subscribe to
CameraView.MediaCaptured:PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PR