2D drawing in a UWP program using win2d (ii)

Source: Internet
Author: User

Drawing API

First, let's look at an example of the previous article:

args. Drawingsession.colors. black     args.drawingsession. (. yellow

It uses the Drawingsesion command, similar to the DrawingContext in WPF, is a drawing context. Its main commands are divided into the following two kinds: drawxxx and fillxxx. Drawxxx just paints the image, and fillxxx only fills the image, which is slightly different from the way WPF paints and fills in an API.

Because the API is not many, here are listed, basically look at to know how to use.

    • Drawcircle
    • Drawcachedgeometry
    • DrawEllipse
    • Drawgeometry
    • DrawImage
    • Drawink
    • DrawLine
    • DrawRectangle
    • Drawroundedrectangle
    • DrawText.
    • Drawtextlayout

    • Fillcircle
    • FillEllipse
    • Fillgeometry
    • FillRectangle
    • Fillroundedrectangle

Its API is relatively simple, basically look at know how to use, but the DrawImage can pass in a icanvasimage type, and this type is not just pictures, including the canvascommandlist and effect described below are this type, You need to familiarize yourself with it.

Conversion

The process of drawing is often accompanied by a number of translation, rotation, such as the operation of the conversion, Drawingsession provides a transform attribute can be passed into a 3*2 matrix to achieve 2D conversion.

VarDS =Args.Drawingsession;

Ds.Transform=matrix3x2.Createtranslation(NewVector2(200, 100));
Ds.DrawText(A, 0, 0,colors. White
    ds. *= matrix3x2.< Span style= "color:olive;" >createrotationvector2     ds. drawtext (, 0, 0, colors. White

Canvascommandlist

Canvascommandlist can cache a set of drawing commands and then draw uniformly. It can be used for block drawing, or it can be used to reduce the repetition of drawing.

VarRenderTarget =NewCanvascommandlist(Sender);
Using(VarCLDs = RenderTarget.Createdrawingsession())
{
CLDs.drawellipse (155, 115, 80, 30, colors. Black         clds. drawtext (. yellow     }

    args.drawingsession.

Filter effects

Win2d A comparison of the characteristics of the force is to support the filter effect, using it can be very convenient to achieve commonly used blur, shadow and other effects, here with the Gaussian blur as an example to modify the above effect.

VarCmdlist =NewCanvascommandlist(Sender);
Using(VarCLDs = cmdlist.Createdrawingsession())
{
CLDs.DrawEllipse(155, 115, 80, 30,Colors.Black, 3);
CLDs.DrawText(. yellow     }

    var effect = newgaussianblureffect () ;
    effect. source = Cmdlist;

    args.drawingsession.

The system also incorporates a number of commonly used filter effects, which end with effect and are placed under the Microsoft.Graphics.Canvas.Effects namespace.

Drawing events

In addition to the draw event that triggers the draw operation when drawing is used earlier, there is a more common event createresource, which is triggered when the control is first loaded, and is often used to initialize various resources.

Another look at the trigger condition of the draw event, which is basically the same as the WPF OnRender, that is, usually triggered when the initial load, changing the window size will be triggered when dragging the window will not be triggered. If you want to control its redraw in the background is also relatively simple, but with its invalidate method.

2D drawing in a UWP program using win2d (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.