Linked Questions

Popular Questions

Using Camera by C++/WinRT

Asked by At

I want to use Camera(CameraCaptureUI or MediaCapture class) in C++/WinRT.

Microsoft document sample code is written by C# and JavaScript.

https://docs.microsoft.com/en-us/uwp/api/Windows.Media.Capture.CameraCaptureUI#code-snippet-1


MFC + C++/WinRT

void CWinRTtestDlg::OnBnClickedButtonToast()
{
    // show toast
    auto notificationManager = ToastNotificationManager::GetDefault();
    auto toastXml = ToastNotificationManager::GetTemplateContent(ToastTemplateType::ToastText01);
    auto textNode = toastXml.GetElementsByTagName(L"text").Item(0);
    textNode.AppendChild(toastXml.CreateTextNode(L"Hello C++/WinRT!"));
    auto toast = ToastNotification(toastXml);
    toast.ExpirationTime(winrt::clock::now() + std::chrono::hours() * 2);
    notificationManager.CreateToastNotifier().Show(toast);
}

this code is working.

IAsyncAction Camera()
{
    auto cameraManager = CameraCaptureUI();
    cameraManager.PhotoSettings().CroppedAspectRatio(Size(4, 3));
    cameraManager.PhotoSettings().Format(CameraCaptureUIPhotoFormat::Jpeg);
    auto file{ co_await cameraManager.CaptureFileAsync(CameraCaptureUIMode::Photo) };
}

void CWinRTtestDlg::OnBnClickedButtonCamera()
{
    winrt::init_apartment();
    auto image = Camera();
}

but this code is NOT working...


C++ project setting
Additional Option /await
C++ Language Standard C++17
Conformance mode No

Related Questions