The first step is to draw the outline of the circle. Because this particular graphic image contains two different colors, the job needs to be done in two steps. The goal here is to draw a red circle filled with blue. An overload lets you specify a background color for the canvas. The Clear method clears the canvas with a transparent color. Here's a typical start of a PaintSurface event handler: void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) The SKCanvas object encapsulates a graphics state, which includes graphics transforms and clipping. This class is a graphics drawing context that you use to perform the actual drawing. The most important property of SKSurface is Canvas of type SKCanvas. In this program, the drawing surface is a video display, but in other programs an SKSurface object can also represent a bitmap that you use SkiaSharp to draw on. The SKSurface object represents the drawing surface itself. The SKImageInfo structure contains information about the drawing surface, most importantly, its width and height in pixels. The SKPaintSurfaceEventArgs object that accompanies the event has two properties: This method can be called multiple times while your program is running, so it should maintain all the information necessary to recreate the graphics display: void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) The PaintSurface event handler is where you do all your drawing. You can alternatively combine an SKCanvasView with other Xamarin.Forms View derivatives, as you'll see in other examples. The SKCanvasView occupies the entire content area of the page. SKCanvasView canvasView = new SKCanvasView() ĬanvasView.PaintSurface += OnCanvasViewPaintSurface The following constructor of the class creates an SKCanvasView object, attaches a handler for the PaintSurface event, and sets the SKCanvasView object as the content of the page: public SimpleCirclePage() The SimpleCircle page class derives from ContentPage and contains two using directives for the SkiaSharp namespaces: using SkiaSharp The outline of the circle is red, and the interior of the circle is blue. This code shows how to draw a circle in the center of the page with a radius of 100 pixels. The first page is entitled Simple Circle and invokes the page class SimpleCirclePage. The SkiaSharpFormsDemos program contains all the sample code for this series of SkiaSharp articles. This article introduces the concepts of drawing graphics in Xamarin.Forms using SkiaSharp, including creating an SKCanvasView object to host the graphics, handling the PaintSurface event, and using a SKPaint object to specify color and other drawing attributes. Learn the basics of SkiaSharp drawing, including canvases and paint objects
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |