Skip to content

[CameraCaptureUI] WinUi 3 desktop app doesn't open camera. and is there any way that can open default system camera and capture image #1034

Closed

Description

@sangitamalviya

CameraCaptureUI captureUI = new CameraCaptureUI();

        StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

        if (photo != null)
        {
            CameraCapture.Source = new BitmapImage(new Uri(photo.Path));
        }

CameraCaptureUI it doesn't open camera. even CaptureElement does not find on UI
Capture (2)

Activity

  1. jgkumaran commented on Jul 14, 2021

    @jgkumaran
    Contributor

    I think CameraCaptureUI requires you to invoke IInitializeWithWindow and pass the window handle.

  2. sangitamalviya commented on Jul 19, 2021

    @sangitamalviya
    Author

    hi @Jaiganeshkumaran , https://gist.github.com/wbokkers/cc8bcc7bc5a646b82a4d41b337330c69 here FileOpenPicker IInitializeWithWindow . I was same tried for CameraCaptureUI IInitializeWithWindow,but it's giving Exception "Element Not Found".I do not know CameraCaptureUI have different Guid or not.

  3. jonwis commented on Jul 19, 2021

    @jonwis
    Member

    Looks like the CameraCaptureUI does not support IInitializeWithWindow, and expects the caller to be on a CoreWindow thread. The implementation uses multiple pickers and launchers that need the "with window" treatment. It's an interesting candidate for open-sourcing the implementation for improvement.

  4. craigomatic commented on Aug 12, 2021

    @craigomatic

    Is there any workaround in the meantime?

  5. applefanbois commented on Dec 29, 2021

    @applefanbois

    Just do exactly like Apple and everything will be fine. I know this new Windows SDK is 15 years behind the SDK of Android and Apple, so I won't be too mean. Our app cannot release until we have access to the camera, we need to be able to scan documents with a camera.

  6. jgkumaran commented on Dec 29, 2021

    @jgkumaran
    Contributor

    Looks like the CameraCaptureUI does not support IInitializeWithWindow, and expects the caller to be on a CoreWindow thread. The implementation uses multiple pickers and launchers that need the "with window" treatment. It's an interesting candidate for open-sourcing the implementation for improvement.

    CameraCaptureUI is probably implemented as a wrapper on Launcher::LaunchUriForResultsAsync as it opens the Windows Camera app in a modal dialog, but Launcher::LaunchUriForResultsAsync doesn't work in desktop apps.

  7. JoeyLiang-0 commented on Jan 19, 2022

    @JoeyLiang-0

    Any update on this issue?

  8. applefanbois commented on Jan 19, 2022

    @applefanbois

    No, surely things will get resolved over time. After all, the hide-task-bar is still not working half the time 25 years later in Windows 11.

  9. janseris commented on Jun 10, 2022

    @janseris

    Jon Wiswall (@jonwis) What happens with this issue, please? This bug is now included in official release of .NET MAUI. That's not good.

  10. XeonKHJ commented on Jun 16, 2022

    @XeonKHJ

    Still wating for this issue to be resolved.

  11. 27 remaining items

  12. Saharsh979 commented on Dec 3, 2024

    @Saharsh979
    Contributor

    Hi everyone,
    We’ve added a new CameraCaptureUI API as part of the WASDK 1.7 Experimental 1 release. The updated API is now available, and we've also added samples for both C++ and C# to demonstrate its usage.
    WindowsAppSDK-Samples/Samples/CameraCaptureUI at release/experimental · microsoft/WindowsAppSDK-Samples

    To test, please retarget your project to WASDK version 1.7.241114004-experimental1.

    As an optional step, you can enable the "Send diagnostic data" option to help us gather data on the API’s reliability. Please check this box under: Privacy & security -> Diagnostics & Feedback -> Send Optional Diagnostic data!
    We’d appreciate your feedback on whether the samples and API usage are clear, and if the fix works as expected

  13. nikolayvpavlov commented on Dec 4, 2024

    @nikolayvpavlov

    CameraCaptureUI cameraUI = new CameraCaptureUI(windowId);
    This is not pleasant and something that should be improved. It must be possible to pass the current page / window / parent in the constructor, and it should be able to do the rest automatically.

    var file = await cameraUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
    It is a bit limiting that we can only capture on a file. Is it possible to extend the functionality of UWP, and capture on a stream?

    Last, but not least: all these helpers in MainWIndow.xaml.cs must be integral part of the API without need for interop with Win32.

  14. mattleibow commented on Dec 4, 2024

    @mattleibow
    Member

    I think in the old days, UWP was sort of a "single window" world, so none of this mattered. But with WinUI and all the multi-window worlds, a modal dialog has to block some window and thus you need to specify which one.

    Some magic could be added if you only have one window, then just use that. But, this now adds a layer of "worked when I did this, but now crashes with missing window errors" because the first test you only had 1 window, and the second test you had 3 windows.

    I think it all has to do with the modal window idea. Maybe this API should not be blocking and have a non-modal option? So if you don't pass in a window ID then it just pops up a dialog with no blocking of the other windows.

  15. Saharsh979 commented on Dec 10, 2024

    @Saharsh979
    Contributor

    Hi Nikolay Pavlov (@nikolayvpavlov)
    Thank you for taking the time to test the new CameraCaptureUI API and for sharing your valuable feedback!

    Regarding your points:

    WindowId Constructor Parameters: We appreciate your suggestion to make the constructor more intuitive by passing the current page/window/parent directly. However, for now, we’ve kept the windowId parameter to ensure to support WinUi3 AppWindow (has Id()) & Window, and also Win32 apps which might be using HWNDs. Could you elaborate on the difficulties you see with the WindowId?

    Capture on Stream: Great feedback. For WASDK1.7 release, our primary goal is to uplift the original UWP CameraCaptureUI API and support it in the WinAppSDK. We will explore it in upcoming release.

  16. Saharsh979 commented on Dec 10, 2024

    @Saharsh979
    Contributor

    Matthew Leibowitz (@mattleibow) Thank you for sharing your thoughts.

    We believe the current behavior of blocking the window is by design. The CameraCaptureUI flow is intended to be a modal interaction, meaning it should start and complete before allowing other user interactions. This ensures the camera capture process is smooth and doesn’t conflict with other UI actions, there also might be hardware limitations.

    Could you elaborate on the issue you mentioned: "worked when I did this, but now crashes with missing window errors"?

  17. nikolayvpavlov commented on Dec 16, 2024

    @nikolayvpavlov

    Hi Saharsh Ananta Jaiswal (@Saharsh979) ,

    Many thanks for following up.

    Regarding your points:

    WindowId Constructor Parameters: We appreciate your suggestion to make the constructor more intuitive by passing the current page/window/parent directly. However, for now, we’ve kept the windowId parameter to ensure to support WinUi3 AppWindow (has Id()) & Window, and also Win32 apps which might be using HWNDs. Could you elaborate on the difficulties you see with the WindowId?

    The problem is not in the constructor, but the whole effort that must be taken in advance to retrieve the current window id. Quoting your sample:

                // We have exposed a public variable called MainWindow in App.xaml.cs to fetch the window.
                var windowId = ((App)Application.Current).MainWindow.AppWindow.Id;
    

    The comment speaks a lot. One must customize your App class just to get the main window in order to get the Window Id. It will not work if we have a multi-window app where developers must store the instance of each window and implement a way to find the right instance they need. Several APIs rely on window id to work (all that require a CoreWindow, if I am not mistaken). WinUI must provide an easy way to get the current window (based on parenthood).

    Perhaps the Window (Id) can be propagandized down to certain controls which are typically the main containers and whose code-behind orchestrate the behavior, such as Page, Alternatively there can be some helpers to find the window id based on parenthood. Such common tasks must not be off-loaded to developer to reinvent all the time. For example, UIElement may have a method like GetWindow() which returns their container window, if any, or null.

  18. lhak commented on Dec 16, 2024

    @lhak

    The XamlRoot.ContentIslandEnvironment.AppWindowId() method should give you the window for a certain UI element.

  19. added
    area-Graphics
    and removed on Nov 5, 2025
  20. changed the title [-]WinUi 3 desktop app doesn't open camera. and is there any way that can open default system camera and capture image[/-] [+][CameraCaptureUI] WinUi 3 desktop app doesn't open camera. and is there any way that can open default system camera and capture image[/+] on Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-Graphicsfeature proposalmaui-7.xtheme-UwpParity

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions