CanvasRenderTargetCreateDrawingSession Method |
Namespace: Microsoft.Graphics.Canvas
CanvasRenderTarget is useful for offscreen rendering.
Note that drawing work is not usually actually carried out by the GPU until the returned drawing session object is closed. In C# this is typically done with a 'using' statement, or in C++/CX the 'delete' keyword. Be sure to close the drawing session before using the rendertarget as a source for some other operation (for example DrawImage Overload, SaveAsync Overload, or CopyPixelsFromBitmap Overload).
Like CanvasBitmap, CanvasRenderTargets are created against an ICanvasResourceCreator, such as a device or control.
CanvasRenderTarget renderTarget = new CanvasRenderTarget(canvasControl, 100, 150); using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) { drawingSession.Clear(Colors.Blue); }
Or if you are programming in C++/CX:
CanvasRenderTarget^ renderTarget = ref new CanvasRenderTarget(canvasControl, 100, 150); CanvasDrawingSession^ drawingSession = renderTarget->CreateDrawingSession(); drawingSession->Clear(Colors::Blue); delete drawingSession;