m_collard
m_collard

Reputation: 2028

Microsoft Screen Capture – C# UWP application

On the following Microsoft Screen Capture link it shows example C# UWP app code. https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/screen-capture

I can’t compile the Putting it all together example code at the bottom of the page.

This showed the Microsoft.Graphics namespace was missing from the project when I tried to compile it. So I searched for Microsoft.Graphics in the NuGet Manager and installed Microsoft.Graphics.Win2D package (v1.0.5.1) by Microsoft.

This fixed most of the compile errors, but it showed there were still errors. One of them being the error on the following line:

_compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(
    Window.Current.Compositor,
    _canvasDevice);

The compiler outputted:

Argument 1: cannot convert from 'Windows.UI.Composition.Compositor' to 'Microsoft.UI.Composition.Compositor'

Window.Current.Compositor returns Windows.UI.Composition.Compositor type whereas the CanvasComposition.CreateCompositionGraphicsDevice method is expecting Microsoft.UI.Composition.Compositor type as the 1st argument.

Can someone please tell me what I need to reference or do to get the example code to compile? Thank you

Upvotes: 0

Views: 604

Answers (1)

Junjie Zhu - MSFT
Junjie Zhu - MSFT

Reputation: 3024

You need to use Win2D.uwp in UWP. The Microsoft.Graphics.Win2D you installed is for use with WinUI3 and Project Reunion.

Win2D currently has two packages available:

  • Win2D.uwp

For use with the WinUI2 (Universal Windows Platform only)

  • Microsoft.Graphics.Win2D

For use with WinUI3 and Project Reunion

Upvotes: 1

Related Questions