Introduction |
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.
Where to get it:
How to use it:
More info:
Download and install Visual Studio:
Create your project:
Add the Win2D NuGet package:
Add a CanvasControl to your XAML page:
xmlns:canvas="using:Microsoft.Graphics.Canvas.UI.Xaml"
<Grid> <canvas:CanvasControl Draw="CanvasControl_Draw" ClearColor="CornflowerBlue"/> </Grid>
Then add some Win2D drawing code.
using Microsoft.UI; using Microsoft.UI.Xaml.Controls; using Microsoft.Graphics.Canvas.UI.Xaml; public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); } 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); } }
void CanvasControl_Draw(Microsoft::Graphics::Canvas::UI::Xaml::CanvasControl^ sender,
Microsoft::Graphics::Canvas::UI::Xaml::CanvasDrawEventArgs^ args);
#include "pch.h" #include "MainPage.xaml.h" using namespace App1; using namespace Windows::UI; using namespace Microsoft::Graphics::Canvas::UI::Xaml; MainPage::MainPage() { InitializeComponent(); } 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); }
Imports Windows.UI Imports Windows.UI.Xaml.Controls Imports Microsoft.Graphics.Canvas.UI.Xaml Public NotInheritable Class MainPage Inherits Page Public Sub New() Me.InitializeComponent() End Sub Private 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 End Class
If you prefer to build your own version of Win2D from source, see the readme for instructions on how to clone from GitHub and compile it locally.
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.