First, create a canvas
Method 1:
this. CreateGraphics ();
Method 2:
New= graphics.fromimage (bitmap);
Picbtrackreplay.image = bitmap;//Specifies the control picture
Using also enables automatic resource recycling of the canvas.
Second, create a brush
1. Creating brushes
using New 2 ) ) { // draw statement }
2. Custom Dash Spacing
Pen Gridpen = new Pen (color, 1); Float[] D = new float[2]; D[0] = 3; D[1] = 3; Gridpen. DashPattern = D; Gridpen. DashStyle = DashStyle.Custom;
3. Custom Arrow Format
New Adjustablearrowcap (44truenew2= LineCap;
Third, drawing
list<pointf> changedpointslist=New list<pointf>();
Draw the line G. DrawLines (RedPen, Changedpointslist.toarray ());
G.drawline (RedPen, New PointF, New PointF (3,4));
Draw a rectangle
G.drawrectangle (Redpen,new PointF, 1, 1);
Drawing polygons
G.drawpolygon (Redpen,changedpointslist.toarry ());
Draw text
g.DrawString ("string", New Font ("Arial", 9), Brushes.black, new PointF);
Fill Color
G.fillpolygon (Brushes.black,changedpointslist.toarry ());
Four, canvas coordinate translation
Screen coordinates:
The upper-left corner of the screen is the origin, the x-axis is horizontal, and the vertical is the y-axis.
Change the Origin position.
G.translatetransform (dx,dy); // Flip Y-axis g.scaletransform (1,-1);
Use of GDI +