Maui
Maui copied to clipboard
[BUG] Captured image in CameraView is Larger than camera preview
Current Behavior
When using CommunityToolkit.CameraView
, the image captured is larger than the preview displayed on the camera page. This results in a mismatch between the visible area in the CameraView
and the actual captured image.
CameraView:
Result:
Expected Behavior
The captured image should match the preview area displayed in the CameraView
.
Steps To Reproduce
- Implement the
CameraView
as shown below:
XAML:
<toolkit:CameraView x:Name="CameraView"
VerticalOptions="Fill"
HorizontalOptions="Fill"
CameraFlashMode="Off"
MediaCaptured="OnMediaCaptured" />
C# Code Behind:
protected override async void OnAppearing()
{
base.OnAppearing();
await _cameraProvider.RefreshAvailableCameras(CancellationToken.None);
CameraView.SelectedCamera = _cameraProvider.AvailableCameras
.FirstOrDefault(c => c.Position == CameraPosition.Rear);
}
private async void OnCaptureButtonClicked(object sender, EventArgs e)
{
if (!CameraView.IsAvailable)
{
await DisplayAlert("Camera Unavailable", "Camera is not available.", "OK");
return;
}
try
{
await CameraView.CaptureImage(CancellationToken.None);
}
catch
{
// Ignore exceptions
}
}
private async void OnMediaCaptured(object? sender, MediaCapturedEventArgs e)
{
try
{
using var stream = (MemoryStream)e.Media;
_stateService.CapturedPhotos.Add(stream.ToArray());
}
catch
{
// Ignore exceptions
}
}
- Capture an image using the
CameraView
.
Environment
- .NET MAUI CommunityToolkit: 9.1.0
- .NET MAUI CommunityToolkit.Camera: 1.0.5
- OS: MacOS Sequoia 15
- .NET MAUI: 9.0.0-rc.2.24503.2
Anything else?
Same issue in another Camera related repo: https://github.com/hjam40/Camera.MAUI/issues/98