1.02k likes | 1.38k Views
Brown Bag Seminar Summer 2007 WPF-Visuals. By Kester Marrain. 2D Graphics. Three layers of 2D Graphics: Shapes Drawings Drawing Instructions All 2D operations boils down to: A Geometry A Brush A Pen. Principles of 2D. Composite Rendering - allow elements to paint on top of each other.
E N D
Brown Bag SeminarSummer 2007WPF-Visuals By Kester Marrain
2D Graphics • Three layers of 2D Graphics: • Shapes • Drawings • Drawing Instructions • All 2D operations boils down to: • A Geometry • A Brush • A Pen
Principles of 2D • Composite Rendering - allow elements to paint on top of each other. • Resolution Independence – uses logical pixels, which equate to 1/96 of an inch. • Pixel Snapping – render with the logical system but when translated to the output device, lines are made to fall exactly on pixels.
Transforms • Three most common transforms are: • TranslateTransform • ScaleTransform • RotateTransform • Transforms can also be combined.
Geometry • Are the basic building blocks of all 2D graphics in WPF.
Geometry (continued) • Two final geometries are the combining geometries: • CombineGeometry • GeometryGroup
Color • sRGB (standard RGB) – is the native color model for most monitors, and it is the default color model for the Web. • Allows for 3 channels of data, each having 8 bits. • scRGB – is a variable size floating-point encoding for color. • All the encoding support an alpha field.
Brushes • WPF has six brushes: • SolidColorBrush • LinearGradientBrush • RadialGradientBrush • ImageBrush • DrawingBrush • VisualBrush
Tiling Brush • ImageBrush, DrawingBrush and VisualBrush are all tiling brushes, they are designed to stretch, or repeat a pattern. • Three operations are used with tiling brushes: • Selecting the content to tile (Viewbox and ViewboxUnits). • Scaling the content (Viewport, ViewportUnits, AlignmentX, and AlignmentY). • Filing the Area with the viewport.
Visual Brush • Visual brushes accept any control and uses it as its source.
Pens • Pens are used to outline shapes.
Drawings • Drawings are the API for directly talking to the low-level composition engine. • Uses a graph structure which allows a single drawing to appear in multiple places.
Shapes • Shapes bring drawing into the control world.
Image • Anything derived from ImageSource in WPF is classified as an Image. • Images have a natural size and metadata associated with it. • WPF has no formal notion of a vector image file format. • However, DrawingImage type offers the ability to use any drawing as an image.
Basic Imaging • Image can be stretched using one of four options: • None: Image is displayed with its natural size. • Fill: The image is scaled to fit entire space. • Uniform: Image made to fit one direction or the other maintaining aspect ratio. • UniformToFill: The image is made to fit the entire space.
Image Metadata • Inclusion of all sorts of information about photographs taken with a digital camera. • Every ImageSource object has a metadata property. • Metadata has two views: • A simplified view of well-known properties • And a query API (GetQuery).
Creating Images • To programmatically generate a raster image, we can use either RenderTargetBitmap or WritableBitmap. • RenderTargetBitmap allows rendering any visible display to a fixed-size raster image.
Opacity • Because opacity composition requires reading of previously rendered display, large portions of an application may be forced into software rendering.
Opacity Mask • Applies opacity to a tree of visuals. • Any brush can be used to apply opacity to a set of visuals.
Bitmap Effects • The ability to perform pixel-by-pixel operations on the output of visuals is usually supported by the BitmapEffect property on UIElement.
3D Graphics • Visual3D is the 3D equivalent of Visuals. • Model3D is the equivalent of Drawing. • 3D lacks a control framework. • 3D inherently has four basic concepts: • Models • Materials • Lights • Camera
3D Graphics (continued) • Models and materials have simple corollaries in the 2D world: Drawings and Brushes. • Geometry3DModel represents a 3D version of a geometry. It is exactly like GeometryDrawing in 2D.
Principles of 3D - Models • All 3D objects eventually are decomposed to a set of triangles. • All texts, shapes, controls, drawings – everything is rendered as 3D triangles. • For all 2D constructs the decomposition is done behind the scenes. • The set of 3D triangles that make up a model is called a mesh. • GeometryModel3D and MeshGeometry3D go hand in hand for creating a model.