| 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 Windows apps for Windows 8.1, Windows Phone 8.1 and Windows 10. 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 Windows.UI; using Windows.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 ClassIf 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.