CommunityToolkit / Maui

The .NET MAUI Community Toolkit is a community-created library that contains .NET MAUI Extensions, Advanced UI/UX Controls, and Behaviors to help make your life as a .NET MAUI developer easier
https://learn.microsoft.com/dotnet/communitytoolkit/maui
MIT License
2.2k stars 375 forks source link

[BUG] Camera View control is not refocusing on Android. #2103

Closed AlejandroHV closed 1 week ago

AlejandroHV commented 1 month ago

Is there an existing issue for this?

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

Camera View control is not refocusing on Android. I just created a simple sample project with the Camera view control and ran the application in Android it does not changes focus, the only way to get it working is to switch between the cameras and when the camera loads it gets the focus appropriately but when adding an object closer it does not works. I tested the same feature with the MediaPicker.Default.CapturePhotoAsync() and it worked as expected. I just created a video of the issue on my phonehttps://drive.google.com/file/d/1XDBdl6HkAlS2Eyo2UZYN_GnmuI675hBt/view?usp=share_link. I tested the application in IOS and the focus works appropriately.

Workloads version: maui-tizen 8.0.61/8.0.100 SDK 8.0.300
ios 17.2.8078/8.0.100 SDK 8.0.300
maccatalyst 17.2.8078/8.0.100 SDK 8.0.300
android 34.0.113/8.0.100 SDK 8.0.300

.NET Version: 8

Device: Xiaomi Redmi Note 13 pro+ 5g. OS Version: Xiaomi HyperOS: 1.0.4.0.

` .xaml

pictos commented 1 month ago

@AlejandroHV can you please add a title to this issue?

AlejandroHV commented 1 month ago

@pictos Done

pictos commented 1 month ago

Not sure if it's a bug or something that isn't implemented... I believe that we don't implemented the auto-focus, but need to double check. I believe that you can extend the current camera view to add it on the CameraManager

AlejandroHV commented 4 weeks ago

Hi @pictos. Is there an example of how to extend the CameraManager or any of the tools from the CommunityToolkit. Additionally is there a default image resolution/ quality the Camera View has? For me the quality of the images taken is lower that the regular one control in MAUI.

pictos commented 4 weeks ago

There's no example, AFAIK, but you should be able to inherit from CameraManager and override the necessary code to make it work for you.

about the resolution, on android you can take a look here

Jake-Derrick commented 2 weeks ago

For me, auto focus worked when opening the camera the first time. After stopping and starting the CameraPreview, auto focus would no longer work.

In CameraManager.android.cs there is

//start the camera with AutoFocus
MeteringPoint point = previewView.MeteringPointFactory.CreatePoint(previewView.Width / 2.0f, previewView.Height / 2.0f, 0.1f);
FocusMeteringAction action = new FocusMeteringAction.Builder(point)
    .DisableAutoCancel()
    .Build();

Removing .DisableAutoCancel() fixed the issue for me. CameraManager is internal though, so it would be messy and difficult to try doing this outside of this package

With .DisableAutoCancel() removed it's able to focus on my fingers after stop/start

https://github.com/user-attachments/assets/52b112ef-5c73-402a-857f-dc0bd053af82

With .DisableAutoCancel() it's unable to focus on my fingers after stop/start

https://github.com/user-attachments/assets/f350fa57-d492-4a67-96fc-46769c64dd1b

AlejandroHV commented 1 week ago

@Jake-Derrick @pictos So I would have to branch off the Camera project and make the modifications and then add it to my project?

bijington commented 1 week ago

We should get this change into a PR if it solves the issue