Features of 2D Graphics
- Vector Graphics support – Scales based on Screen specific resolution without loss of quality as opposed to fixed size Raster graphics
- Hardware acceleration – Takes advantage of graphics hardware to minimize CPU usage; Utilizes GPU on Video Card implementing Direct X 7 or later
- Resolution and Device independent graphics – Device independent pixel automatically scales with dots per inch setting
- Minimal screen redraw
- Simplifies Graphics programming – manages screen graph, No worry about screen processing, Rendering loops and bilinear interpolation.
- Hit testing support, Integrated animation system, Full alpha compositing support
- Improved Precision – Uses doubles than floats for coordinates even for Transformations and Opacities; Floating point logical pixel system;
- Supports wide color gamut(scRGB) ; Supports 32 bit ARGB colors
- Integrated support for managing input from different color spaces
- Uses Direct 3D for Vector based Rendering
Windows Forms used different services like
- GDI/GDI+ for 2D graphics
- UI services/user32 for UI
- Direct 3D for 3D Graphics
WPF unites all these services.
Shape is a UIElement that draws a shape in screen and can be used inside Panel and other controls. The different shapes available are Ellipse, Line, Path, Polygon, Polyline, Rectangle. The properties of Shape are
- Stroke – How Shape’s outline is painted
- StrokeThickness – thickness of Shape’s outline
- Fill – How Shape’s interior is painted
- Coordinates and Vertices
Canvas Panel supports absolute Positioning and is a good choice for Complex drawings.
Line class draws a line between two points. Settings Line’s Fill property does nothing.
Ellipse is defined by Width and Height.
Path class draws curves and complex shapes, which are described by Geometry objects. Create a Geometry and set it to Path’s data property. LineGeometry, RectangleGeometry and EllipseGeometry are simple shapes. Complex shapes can be created using PathGeometry class.
PathGeometry class is composed of many PathFigure objects, each describing a different shape. Each PathFigure object contains many PathSegment objects, each describing a connected portion of a figure or shape. The different segments are LineSegment, BezierSegment and ArcSegment.
Brush objects are used to paint a Shape’s stroke and Fill properties, which contain a hexadecimal color properties, denoting the color of brush.
Line, Path, Polygon, Polyline and Rectangle have Stretch property, which determines how a Shape’s object’s contents is stretched to fill the shape of Shape’s object layout space, the amount of space the Space is allocated by the layout system, through Height, Weight, Horizontal Alignment and Vertical Alignment. Stretch property can be None, Fill (fills with different aspect ratio), Uniform (scales with same aspect ratio) and Uniform to Fill (fills with aspect ratio). When the contents are stretched, the object outline is painted after stretching.
Shapes can be transformed using Transform class which can be RotateTransform (Rotation), ScaleTransform (scale), SkewTransform (skew) and TranslateTransform (translation). RotateTransform can be specified using Angle and a point with X and Y values about which the element needs to rotated.
A Brush paints the Visible objects in a screen with solid colors to complex sets of patterns and images. The different brushes are
- SolidColorBrush – Paints an area with solid color
- LinearGradientBrush – Paints an area with Linear Gradient; Linear Gradient blends two or more colors across a line, gradient axis. GradientStops specifies the colors in the gradient and their positions.
- RadialGradientBrush – Paints an area with Radial Gradient; Radial Gradient blends two or more colors across a circle. GradientStops specifies the colors in the gradient and their postitions.
- ImageBrush – Paints an area with ImageSource
- DrawingBrush – Paints an area with Drawing; Drawing contains shapes, images, text and media;
- VisualBrush – Paints an area with Visual object like Button, Page, MediaElement; Enables to project content from one portion of application into another area; creates Reflection effects and magnifying portions of screen;
The Brush properties for different visual objects are:
- Border – BorderBrush, Background
- Control – Background, Foreground
- Panel – Background
- Pen – Brush
- Shape – Fill, Stoke
- Textblock – Background
Brushes contain Opacity property that makes Brushes transparent (0) or partially transparent or opaque (1); Brushes contain Opacity property and color inside Brushes also contain Opacity property. The final Opacity is arrived by multiplying Opacity values of Brush and color.
Brush content can be rotated, scaled, skewed and translated using Transform objects.
Brushes are animatable objects and can be animated.
Brushes inherit from Freezable class and hence can be declared as resources, shared among multiple objects and cloned.
All Brushes except Visual Brush can be made Readonly to improve performance.
Drawing object describes the visible content like shape, bitmap, video or text. The different drawing objects are
- GeometryDrawing – Draws a shape
- ImageDrawing – Draws an image
- GlyphRunDrawing – Draws text
- VideoDrawing – Plays audio or video text
- DrawingGroup – Draws other drawings; Combines many drawings into a single composite drawing
Drawing objects are created in different ways like
- Display an image using DrawingImage and Image Control
- Paint an object with DrawingBrush
- Describe the Appearance of DrawingVisual
- Enumerate the contents of a Visual
They are of type Freezable and lack support for Layout System, input and Focus and hence in case of Performance need and for low level drawing.
Check out more on http://msdn.microsoft.com/en-us/library/ms751619.aspx
A Transform defines how to map or transform coordinates from one coordinate space to other coordinate space. This mapping is defined by Transformation Matrix, a collection of three rows with three columns of Double values. By manipulating matrix values, an object can be rotated, scaled, skewed and translated/moved.
The different Transforms are
- RotateTransform – rotates an element by specified angle
- ScaleTransform – scales an element by specified X and Y amounts
- SkewTransform – skews an element by specified AngleX and AngleY amounts
- TranslateTransform – translates an element by specified X and Y amounts.
TransformGroup groups multiple TransformGroup objects into a single Transform which can be applied
MatrixTransform creates custom transforms which are not provided by other Transform classes by manipulating a matrix.
Transformation properties of different objects are as follows:
- Brush – Transform, RelativeTransform
- ContainerVisual – Transform
- DrawingGroup – Transform
- FrameworkElement – RenderTransform, Layout Transform
- Geometry – Transform
- TextEffect – Transform
- UIElement – RenderTransform
Layout Tranform is the transform applied before the layout pass. After appllying the transform, the layout system processes the transform size and position of the element.
Render Transform is the transform that modifies the appearance of the element after the layout pass is complete.
Check out more on http://msdn.microsoft.com/en-us/library/ms750596.aspx