WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

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

Open sangitamalviya opened this issue 4 years ago • 34 comments

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)

sangitamalviya avatar Jul 03 '21 08:07 sangitamalviya

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

jaigak avatar Jul 14 '21 12:07 jaigak

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.

sangitamalviya avatar Jul 19 '21 18:07 sangitamalviya

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.

jonwis avatar Jul 19 '21 19:07 jonwis

Is there any workaround in the meantime?

craigomatic avatar Aug 12 '21 22:08 craigomatic

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.

applefanbois avatar Dec 29 '21 13:12 applefanbois

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.

jaigak avatar Dec 29 '21 13:12 jaigak

Any update on this issue?

JoeyLiang-0 avatar Jan 19 '22 13:01 JoeyLiang-0

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.

applefanbois avatar Jan 19 '22 14:01 applefanbois

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

janseris avatar Jun 10 '22 17:06 janseris

Still wating for this issue to be resolved.

XeonKHJ avatar Jun 16 '22 09:06 XeonKHJ

+1 here. One of the reasons that lead us to believe in MAUI is the possibility of using the HW of the devices, the camera is the most important among them.

aletfa avatar Jul 15 '22 11:07 aletfa

@jonwis any progress?

janseris avatar Jul 15 '22 11:07 janseris

So, is this bug the reason why the "Camera" permission is listed as not supported for Windows on this MAUI docs page? https://docs.microsoft.com/en-us/dotnet/maui/platform-integration/appmodel/permissions?tabs=ios#available-permissions This is a pretty important feature to be missing on a platform.

bit-wrangler avatar Sep 12 '22 02:09 bit-wrangler

You can use DirectShow (WinUI3_DirectShow_Capture) or Windows Media Foundation or AVICap for camera capture

castorix avatar Sep 12 '22 06:09 castorix

I used CameraCaptureUI with Winui 2 https://docs.microsoft.com/en-us/uwp/api/windows.media.capture.cameracaptureui?view=winrt-22621

sangitamalviya avatar Sep 12 '22 07:09 sangitamalviya

CameraCaptureUI works fine in UWP but doesn't work in WinUI3.

anovik avatar Sep 12 '22 07:09 anovik

Any progress on this? A similar thing is happening for me using the Windows.Devices.PointOfService.PosPrinter API, calling PosPrinter.FromIdAsync(deviceInfo.id) returns null in MAUI/WinUI3. Exactly the same code, with the same pointOfService capability enabled in the mainifest, works fine with Xamarin Forms/UWP.

This would normally pop up a dialog for the user to confirm they want to pair with the printer, so I'm guessing this is a similar issue to this:

https://github.com/microsoft/WindowsAppSDK/issues/1034#issuecomment-882796594

1888games avatar Sep 14 '22 13:09 1888games

Any progress on this? A similar thing is happening for me using the Windows.Devices.PointOfService.PosPrinter API, calling PosPrinter.FromIdAsync(deviceInfo.id) returns null in MAUI/WinUI3. Exactly the same code, with the same pointOfService capability enabled in the mainifest, works fine with Xamarin Forms/UWP.

This would normally pop up a dialog for the user to confirm they want to pair with the printer, so I'm guessing this is a similar issue to this:

#1034 (comment)

Don't the docs say that the Windows.Devices.PointOfService namespace is for UWP apps only?

brokenthorn avatar Sep 19 '22 12:09 brokenthorn

Well, they come under /UWP in the docs hierarchy but it seems strange that this whole swathe of useful, generic device functionality is only available to UWP apps. If it is UWP only, the namespace Windows.Devices.PointOfService is not very clear, it suggests to me that any Windows app whether written in C++, C# or VB.Net, and using any UI framework, should be able to use it.

It's not like we have a choice - Xamarin is being deprecated, UWP is clearly being phased out and MAUI only supports WinUI3. Two years into a project to port a legacy system to modern cross-platform technologies we have essentially had the rug pulled from under us.

After all, most of this stuff - cash drawers, stripe readers, receipt printers etc - does not require any UI, especially in a non-sandboxed world outside of UWP. The dialog that asks you to pair with the printer (it's not even bluetooth, just ethernet) is completely unnecessary in a commercial environment, it preferably just gets done silently in the background.

Fortunately one of the brand of printers we use has their own SDK but we switched away from that to give us the flexibility to switch to any other brand that supports the POS standard. Hopefully there will be no issues with switching back...

1888games avatar Sep 19 '22 18:09 1888games

In case any one else is working with receipt printers, cash drawers etc, we have now switched to the ESC-POS.NET library: https://github.com/lukevp/ESC-POS-.NET

It's not a particularly smooth process - we first get a list of network printer MAC addresses using the PointOfService API as before. Then use that to get the IP address corresponding to the MAC via some stackoverflow magic, before finally being able to connect to the printer using ESC-POS and build the receipt.

1888games avatar Sep 22 '22 06:09 1888games

I'm having the same issue while developing in .NET Maui. Using the .NET Maui Apis, I need to be able to use both MediaPicker.Default.CapturePhotoAsync() and MediaPicker.Default.CaptureVideoAsync() to take a photo and video.

According to the documentation it should work in Windows: https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/device-media/picker?tabs=windows ...but it doesn't work.

Any progress fixing things?

david-palladino avatar Sep 24 '22 13:09 david-palladino

I'm having the same issue while developing in .NET Maui. Using the .NET Maui Apis, I need to be able to use both MediaPicker.Default.CapturePhotoAsync() and MediaPicker.Default.CaptureVideoAsync() to take a photo and video.

According to the documentation it should work in Windows: https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/device-media/picker?tabs=windows ...but it doesn't work.

Any progress fixing things?

I have the same problems. Any info?

Zacharianel avatar Oct 13 '22 08:10 Zacharianel

My UWP app uses DisplayRequest, CaptureElement, MediaCapture, BarcodeScanner and ClaimedBarcodeScanner to implement a QR code scanner. All of these APIs should be made available by the Windows App SDK.

I know that I could implement this myself in a different way when migrating to the Windows App SDK. But why would I have to? A QR code scanner is such a standard building block that it just makes no sense at all not having it in the Windows App SDK.

ackh avatar Nov 13 '22 10:11 ackh

It is sad that nobody from Microsoft steps in to say when this will be fixed. As a result of WinUI's fault, this is broken in both Maui and Uno. And I must develop an app that captures pictures... Sweet, isn't it.

nikolayvpavlov avatar Dec 13 '22 16:12 nikolayvpavlov

@nikolayvpavlov I haven't tried this myself but I have seen a workaround for taking pictures here. Maybe it helps.

ackh avatar Dec 13 '22 16:12 ackh

@jonwis @btueffers after 6 months I am asking again, any progress? Who is responsible for these issues? Why is (seemingly) noone doing anything? This issue directly affects .NET MAUI.

janseris avatar Dec 16 '22 12:12 janseris

Stop it, don't hurt yourself anymore. Microsoft has abandoned Windows 15 years ago. You should port your app to Android and it will run natively on Windows 11 from the Amazon Store. We are in the same situation, the code is done since 2019 but we are still waiting for MS to provide us with a working webview that support Web 2.0. Webview2 is still not working, It is unusable.

We are stuck with a useless windows app for 3 years now and it will never work. MS is 15 years behind Android, iOS, macOS, Linux... They don't care about new apps. Microsoft is only used to run legacy software nowadays.

Good luck my friend. You should not keep trying at this point, Microsoft does not love you.

applefanbois avatar Dec 16 '22 12:12 applefanbois

I think this PR will fix mui by using the cool community code, but maybe it can somehow be integrated into this SDK? https://github.com/dotnet/maui/pull/13220

mattleibow avatar Feb 10 '23 18:02 mattleibow

one alternative is using the MediaCapture, MediaFrameReader, and relative classes, then, then render each frame to an XAML Image control.

DJRM2021 avatar Feb 16 '23 03:02 DJRM2021

one alternative is using the MediaCapture, MediaFrameReader, and relative classes, then, then render each frame to an XAML Image control.

Or also IMFCaptureEngine that I tested on Windows 10 (WriteableBitmap + Image control), with audio/video recording easy to use (StartRecord does all the work, without implementing IMFCaptureSink)

castorix avatar Feb 22 '23 05:02 castorix