WindowsAppSDK
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
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
I think CameraCaptureUI requires you to invoke IInitializeWithWindow and pass the window handle.
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.
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.
Is there any workaround in the meantime?
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.
Looks like the
CameraCaptureUIdoes not supportIInitializeWithWindow, and expects the caller to be on aCoreWindowthread. 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.
Any update on this issue?
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.
@jonwis What happens with this issue, please? This bug is now included in official release of .NET MAUI. That's not good.
Still wating for this issue to be resolved.
+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.
@jonwis any progress?
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.
You can use DirectShow (WinUI3_DirectShow_Capture) or Windows Media Foundation or AVICap for camera capture
I used CameraCaptureUI with Winui 2 https://docs.microsoft.com/en-us/uwp/api/windows.media.capture.cameracaptureui?view=winrt-22621
CameraCaptureUI works fine in UWP but doesn't work in WinUI3.
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
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:
Don't the docs say that the Windows.Devices.PointOfService namespace is for UWP apps only?
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...
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.
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'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?
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.
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 I haven't tried this myself but I have seen a workaround for taking pictures here. Maybe it helps.
@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.
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.
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
one alternative is using the MediaCapture, MediaFrameReader, and relative classes, then, then render each frame to an XAML Image control.
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)