help with camera preview

Eduardo Gomez 3,431 Reputation points
2023-07-04T19:54:46.6133333+00:00

I don't Know what to do, I am really struggling.

I need to use the webcam, to take a picture of the user, I need to add the camera preview here.

 <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <demy:AppTitleBarControl
            x:Name="AppBar"
            ShowIcon="false"
            Text="Register" />

        <StackPanel
            Grid.Row="1"
            Width="600"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Spacing="20">

            <TextBox
                PlaceholderText="First name"
                Text="{x:Bind ViewModel.User.Name}" />

            <TextBox
                PlaceholderText="Second name"
                Text="{x:Bind ViewModel.User.SecondName}" />

            <TextBox PlaceholderText="Phone Number"
                     Text="{x:Bind ViewModel.User.Phone}"/>

            <TextBox
                PlaceholderText="Email Address"
                Text="{x:Bind ViewModel.User.Email}" />

            <PasswordBox
                Password="{x:Bind ViewModel.User.Password}"
                PasswordRevealMode="Peek"
                PlaceholderText="Password" />

            <PasswordBox Password="{x:Bind ViewModel.User.ConfirmPassword}"
                         PasswordRevealMode="Peek"
                         PlaceholderText="Confirm password" />

//webcam

        </StackPanel>

    </Grid>


and this is my vm

        [ObservableProperty]
        private User user;

        public RegisterWindowViewModel(ILocation _location) {

        }

        [RelayCommand]
        private async void RegisterAsync(User user) {

            //take picture
        }

I tried to use one of these workarounds

https://github.com/microsoft/microsoft-ui-xaml/issues/4710

but that did not work for me or I am doing something wrong

I even tried to use CommunityToolkit.WinUI which has a CameraPreview but I could not get it to work

code: https://github.com/eduardoagr/Demy-AI

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
823 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 86,976 Reputation points
    2023-07-07T11:55:16.7066667+00:00

    I just uploaded a test with another method, by using IMFCaptureEngine :

    WinUI3_MFCaptureEngine

    (only tested on Windows 10)

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.