question

Aleksey-0461 avatar image
0 Votes"
Aleksey-0461 asked JarvanZhang-MSFT answered

How to call camerax from xamarin forms

hello friends
How to call camerax from xamarin forms
Is there a control for this to use in xaml

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered

Hello,​

Welcome to our Microsoft Q&A platform!

Camerax is Android native api which cannot be used in the shared project directly. You could define the function in the Android platform project and then call the function code in the shared project using DependencyService.

If you want to use a camera view in xaml, please try the Xamarin.Community.Toolkit.CameraView control. The CameraView control enables the user to display a preview of the camera output, and it can take photos or record videos. For more details, you could refer to this doc.

<ContentPage ...
             xmlns:xct="http://xamarin.com/schemas/2020/toolkit">

     <StackLayout>

        <xct:CameraView
                x:Name="cameraView"
                CaptureMode="Photo"
                FlashMode="On"
                HorizontalOptions="FillAndExpand"
                MediaCaptured="CameraView_MediaCaptured"
                OnAvailable="CameraView_OnAvailable"
                VerticalOptions="FillAndExpand" />

    </StackLayout>

</ContentPage>


Best Regards,

Jarvan Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.