خرید بک لینک

Vote count: 0

hope its something simple stupid, but I am spiing my wheels.

I have a Surface Pro 4, Windows 10 and using Visual Studio 2013 Professional.
Developing WPF using C# 4.5.

I am trying to do a simple camera capture to save an image without resorting to other 3rd party libraries I have no control over.

I started with https://msdn.microsoft.com/en-us/library/windows/apps/windows.media.capture.cameracaptureui.aspx CameraCaptureUI class

I then found this link https://www.etealcoding.com/?p=183 How to use specific WinRT API from Desktop apps I tried going through all the steps as outlined and getting errors associated with

await ... have a suitable GetAwaiter method.

So, I looked up about asynch and await and came across

how and when to use `async` and `await` how and when to use async and await.

So, I scrapped the first camera capture project, started a new, and did that version that has simple thread.sleep delay to show the concept of asynch / await. That part works.

So now, I add back the reference to the project and manually edit to add the

  <PropertyGroup>
    <TargetPlatformVersion>8.0</TargetPlatformVersion>
  </PropertyGroup>

to expose the References expose the Windows / Core per the first link and then getting access to the Windows.Media, Windows.Storage. I add in just the first little bit of code about the CameraCaptureUI and CaptureFileAsync as just a starting point such as...

private async void Camera1()
{
    var cameraUi = new Windows.Media.Capture.CameraCaptureUI();
    var capturedMedia = await cameraUi.CaptureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.Video);

    if (capturedMedia == null)
        retu;

    MessageBox.Show("Valid Camera");
}

and get a compile error about:

'await' requires that the type 'Windows.Foundation.IAsyncOperation' have a suitable GetAwaiter method. Are you missing a using directive for 'System'?

Also, back to the original Windows version attempt via

private async void Camera2()
{
    CameraCaptureUI dialog = new CameraCaptureUI();
    Windows.Foundation.Size aspectRatio = new Windows.Foundation.Size(16, 9);
    dialog.PhotoSettings.CroppedAspectRatio = aspectRatio;

    StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);
    if (file == null)
        retu;

    MessageBox.Show("Valid Storage File Captured");
}

I even have System.Runtime and System.RunTime.WindowsRuntime as references to the project but still fail on compile.

What am I missing. I know things change between different versions such as Windows 8.1 and Windows 10, and upgrades to features / libraries, but why await works one way, but not another.

asked 41 secs ago

- - , .
.

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 22 تير 1395 ساعت: 1:54

صفحه بندی