[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.
Reproduction Sample
https://github.com/MoienTajik/MauiCameraIssue
Steps To Reproduce
- Implement the
CameraViewas 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
Ok, here's the reproduction project: https://github.com/MoienTajik/MauiCameraIssue
I'm having the same problem.
Any solution?
Hi I'm having the same problem on my Samsung S24F.
Playing around with the different capturing resolutions even in the Sample app - will reproduce this issue.
Sometimes the captured image is only "a part of the preview" - sometimes the captured images is "larger than preview"
Is this specific to some device brands or just a Samsung problem?
Using my old Redmi Note 7 its not an issue
Same Problem - had this problem with Xamarin too! Happens with Android and iOS
My guess is:
- The Live-Preview is using a Video-Feed and so is using a 16:9 ratio and Video-Resolution
- When you take a picture, the camera mode is used with a specified resolution (if set) - but the camera mode will take pictures in 3:2 or 4:5 ratio (should be default; sure there would be 1:1 and other ratios available depending on the device and so on)
If you open the native Camera App on Android for example, you see a Live-Preview with the same Aspect-Ratio and View Angle as the resulting picture! So there has to be a way to force the OS to give you/us a Preview-Feed at the same angle / ratio as we set for the camera-resolution.
I just don't know how 🤔