Click or drag to resize
CanvasRenderTargetCreateDrawingSession Method
Returns a new drawing session. The drawing session draws onto the CanvasRenderTarget.

Namespace:  Microsoft.Graphics.Canvas
Assembly:  Microsoft.Graphics.Canvas (in Microsoft.Graphics.Canvas.dll) Version: 0.0.0.0
Syntax
C#
public CanvasDrawingSession CreateDrawingSession()

Return Value

Type: CanvasDrawingSession
Remarks

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).

Examples

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;
See Also