Win2D is an easy-to-use Windows Runtime API for immediate mode 2D graphics rendering with GPU acceleration. It is available to C#, C++ and VB developers writing apps for the Windows Universal Platform (UWP). It utilizes the power of Direct2D, and integrates seamlessly with XAML and CoreWindow.
Visit the DirectX Landing Page for more resources for DirectX developers.
- Documentation
- Sample code - also available in the Store
To give you a flavor of what the code looks like, here is a snippet of XAML:
xmlns:canvas="using:Microsoft.Graphics.Canvas.UI.Xaml"
<Grid>
<canvas:CanvasControl Draw="canvasControl_Draw" ClearColor="CornflowerBlue" />
</Grid>
and C#:
void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
{
args.DrawingSession.DrawEllipse(155, 115, 80, 30, Colors.Black, 3);
args.DrawingSession.DrawText("Hello, world!", 100, 100, Colors.Yellow);
}
or C++/CX:
void MainPage::CanvasControl_Draw(CanvasControl^ sender, CanvasDrawEventArgs^ args)
{
args->DrawingSession->DrawEllipse(155, 115, 80, 30, Colors::Black, 3);
args->DrawingSession->DrawText("Hello, world!", 100, 100, Colors::Yellow);
}
or C++/WinRT:
void MainPage::CanvasControl_Draw(CanvasControl const& sender, CanvasDrawEventArgs const& args)
{
args.DrawingSession().DrawEllipse(155, 115, 80, 30, Colors::Black(), 3);
args.DrawingSession().DrawText(L"Hello, world!", 100, 100, Colors::Yellow());
}
or VB:
Sub canvasControl_Draw(sender As CanvasControl, args As CanvasDrawEventArgs)
args.DrawingSession.DrawEllipse(155, 115, 80, 30, Colors.Black, 3)
args.DrawingSession.DrawText("Hello, world!", 100, 100, Colors.Yellow)
End Sub
The documentation explains how to install Visual Studio, add the Win2D NuGet package to your project, and get started using the API.
- Visual Studio 2019 16.2 with Tools for Universal Windows Apps 15.0.27428.01 and Windows SDK 18362
- Go to 'View' -> 'Team Explorer' -> 'Local Git Repositories' -> 'Clone'
- Add the Win2D repository URL (https://github.com/Microsoft/Win2D.git) and hit 'Clone'
- Launch 'Developer Command Prompt for VS2019'
- Change directory to your cloned Win2D repository and run 'build'
- In Visual Studio, go to 'Tools' -> 'NuGet Package Manager' -> 'Package Manager Settings'
- Choose 'Package Sources'
- Click the '+' button to add a new source
- Set 'Name' to 'Win2D' (or a name of your choosing)
- Set 'Source' to the full path to the 'bin' directory (inside your cloned Win2D repository)
- Click the 'Update' button
- Click 'OK'
Locally built versions of Win2D are marked as prerelease, so you must change the 'Stable Only' setting to 'Include Prerelease' when adding them to your project.
Win2D 1.21.0 was the last release to support the Windows 8.1 and Windows Phone 8.1 platforms. From Win2D 1.22.0 onward, only the Windows Universal Platform (UWP) is supported.
Legacy Win2D support for Windows and Phone 8.1 is available as a NuGet package and from the win81 branch on github.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.