Practical WPF Charts and Graphics Note_01

Practical WPF Charts and Graphics Note_01

Reference website:
https://www.cnblogs.com/tuyile006/p/7656204.html
https://www.cnblogs.com/tuyile006/p/7656204.html

Geometry

Vector graphics can be drawn in WPF, and will not appear jagged or deformed with the enlargement or reduction of the window or graph type. The following basic graphics are derived from the Shape class :

Line
Rectangle Rectangle Rectangle
Ellipse Oval
Polygon
Polyline Polyline Polyline, not closed
Path path

Path is a relatively important category in drawing, which can replace the several graphics tools above, and can also draw more complex images.
The path not only has attributes such as Stroke, StrokeThickness, but also a key attribute-Data, whose type is Geometry, which can be used to replace other drawing types.
In the WPF graphics system, the Geometry class represents the base class of geometric figures. It is an abstract class. When used, it instantiates some of its subclasses. The specific ones are:

LineGeometry: straight line segment geometry
RectangleGeometry: rectangular geometry
EllipseGeometry: ellipse geometry

The above three are similar to their corresponding Shape classes . You can also set properties to change the shape of the graph.

PathGeometry: Path geometry The
path collection graphics PathGeometry can contain a series of geometric graphics collections, mainly composed of multiple LineSegments (line segments) to form a PathFigure, and multiple PathFigures to form a PathGeometry (geometric). Geometry is composed of graphs, which are surrounded by multiple segments. In addition, one more thing to note is that each segment is the start point of the previous segment. Common ones are:
Line segment: LineSegment
Arc: ArcSegment
Bezier curve::
BezierSegment: Create a cubic Bezier curve between two points.
PolyBezierSegment: Create a series of cubic Bezier curves.
PolyQuadraticBezierSegment: Create a series of quadratic Bezier curves.
QuadraticBezierSegment: Create a quadratic Bezier curve.

StreamGeometry
is a StreamGeometry drawn through a series of APIs. It does not support binding, animation, and is correspondingly more flexible and efficient.

Complex geometry
CombinedGeometry
GeometryGroup

Using GeometryGroup, CombinedGeometry or by calling the static Geometry method Combine, you can create a composite geometry object. The main differences are:

CombinedGeometry superimposes the sub-graphics, and the sub-graphics without area will be discarded. Only two sub-graphics can be combined (but these two sub-graphics can also be composite geometric figures).
GeometryGroup only performs combination, not area overlay. You can add multiple sub-graphics.

The Geometry object itself also contains a series of very useful methods, such as:

GetArea-Get the area of ​​Geometry.
FillContains-Determine whether to include other Geometry.
StrokeContains-Determine whether to include the specified point.
Bounds: Get the bounding rectangle.
These are very common methods. For example, FillContains and StrokeContains are very convenient for mouse hit testing.

ways of presenting

Geometry objects cannot be presented independently as images. They are generally presented
in the following ways: presented in Path: can be presented as a parameter of GeometryDrawing.Geometry as a Path object
presented in DrawingContext: can be presented as a parameter of DrawingContext. DrawGeometry can be presented
in GeometryDrawing Middle rendering: can be rendered as a Drawing object as a parameter of GeometryDrawing.Geometry

Of course, the Drawing object cannot be rendered independently. It is generally used as a DrawingBrush or as a parameter of DrawingContext.DrawDrawing.

Deformation in WPF includes not only stretching, squeezing, zooming in, zooming out, etc., but also changes in size, position, coordinate ratio, and rotation angle. There are two properties that control the transformation:
RenderTransform: Rendering transformation, defined in the UIElement class.
LayoutTransform: Layout transformation, defined in the FrameworkElement class.

Because the FrameworkElement class is derived from the UIelement class, and the base control class Control class is derived from the FrameworkElement class, the FrameworkElement class has two properties. In addition, you must also know that the above two attributes are dependent attributes, and their type is the Transform abstract class. The types derived from this abstract class are as follows:

MatrixTransform: Matrix Deformation
RotateTransform: Rotation Deformation
ScaleTransform: Coordinate Deformation
SkewTransform: Stretch Deformation
TranslateTransform: Offset Deformation
TransformGroup: Deformation Group


PathGeometry usage

XAML (code A):
Insert picture description here

Please pay attention to the bold and red text above. WPF provides two classes to describe path data: one is StreamGeometry and the other is PathFigureCollection.

similar: The form is the XAML code representation of StreamGeometry, and it is also the most concise representation.
And similar:
Insert picture description here
This way is to use the XAML code representation of PathFigureCollection.

Both methods can achieve the same display effect. Generally, when you create a path and no longer need to modify it, you can use the StreamGeometry method. If you need to modify the path value, use the PathFigureCollection method (here is PathGeometry) .
Insert picture description here

The commonly used brush types are:

· SolidColorBrush: Use pure Color to draw the area.
· LinearGradientBrush: Use a linear gradient to draw the area. There is a GradientStop attribute, and you can also check msdn for radial gradients. I think the above is quite clear.
· RadialGradientBrush: Use a radial gradient to draw the area.
· ImageBrush: Use the image (represented by the ImageSource object) to draw the area.
· DrawingBrush: Use Drawing to draw the area. The drawing may contain vector and bitmap objects.
· VisualBrush: Use Visual objects to draw areas. Using VisualBrush, you can copy content from one part of the application to another area, which is very useful when creating reflection effects and zooming in on part of the screen

Guess you like

Origin blog.csdn.net/lm393485/article/details/109047017