-
Notifications
You must be signed in to change notification settings - Fork 456
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
IDisposable
onCameraView
for cleanup ofSemaphoreSlim
- Changes
CaptureImage
toasync Task<Stream>
, usesTaskCompletionSource<Stream>
withMediaCaptured
/MediaCaptureFailed
events - Updates
ICameraView
interface 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
CaptureImage
behavior (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
CaptureImage
now returns aTask<Stream>
instead ofValueTask
and no longer relies on theMediaCaptured
event.
Task<Stream> CaptureImage(CancellationToken token);
Co-authored-by: Copilot <[email protected]>
Description of Change
API Change
This PR updates
ICameraView.CaptureImage()
to return theStream
captured 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)main
at time of PR