Graphics .
NET
10/09/13
Author: Vaibhav, Reviewer: Prasanna
GDI+
GDI+ isn't the only way of displaying graphics using C#. You can use XNA (on Windows or Xbox), there's WPF and Silverlight. Can be achieved by using following namespaces: System.Drawing; System.Drawing.2D; System.Drawing.Printing; System.Drawing.Text;
10/09/13
Author: Vaibhav, Reviewer: Prasanna
How ?
To draw something you have to:
Obtain a Graphics object (the modern name for what in GDI was called a Display context). Draw using the Graphics object methods.
System.Drawing namespace provides access to GDI and basic graphic functionality. Important Classes are : Bitmap,Brush,Font,Graphics,Pen.
10/09/13
Author: Vaibhav, Reviewer: Prasanna
PaintEventArgs in the Paint Event Handler
Create Graphic Method
Create from an Image Object
10/09/13
Author: Vaibhav, Reviewer: Prasanna
Drawing and Manipulating Shapes and Images
The Pen classUsed for drawing lines, outlining shapes, or rendering other geometric representations. The Brush classUsed for filling areas of graphics, such as filled shapes, images, or text. The Font classProvides a description of what shapes to use when rendering text. The Colour structureRepresents the different colours to display.
10/09/13
Author: Vaibhav, Reviewer: Prasanna
Pen
This is an object that represents a pen and is use to draw lines, edges of shapes etc. What we can control : colour, the thickness, the type of line, etc. We can also control Line Pattern of this object(solid,texture). Constructors : Pen(Brush,Colour,Thickness)
10/09/13
Author: Vaibhav, Reviewer: Prasanna
Brush
A Brush (i.e. an instance of System.Drawing) can be one of the following:
SolidBrush with just a color, HatchBrush (for cross hatching with Horizontal, ForwardDiagonal and Cross Hatching) TextureBrush uses a pattern stored in a bitmap. GradientBrush can be linear (LinearGradientBrush) or path (PathGradientBrush)
10/09/13
Author: Vaibhav, Reviewer: Prasanna
How to Draw Line and Outline ?
10/09/13
Author: Vaibhav, Reviewer: Prasanna
10/09/13
Author: Vaibhav, Reviewer: Prasanna
Bitmap and Images
Both can be viewed interchangeably. Image class is an abstract Class, two descendants- Bitmap and MetaFile. Metafiles are for vector graphics using a series of recorded and replayed instructions. Bitmap : Array of Colours. Relation between : Bits per pixel & Number of colours that can be assigned to a pixel. GDI+ provides Alpha Blending(Value 0-255).
10/09/13
Author: Vaibhav, Reviewer: Prasanna
10
Bits per Pixel
8 bits
10/09/13
24 Bits
Author: Vaibhav, Reviewer: Prasanna 11
GDI+ Other features
Text : use Pen , Colour and Brush. Graphics Object : here are three ways to do this :
From the Paint event method argument. Create one by calling CreateGraphics method of a control or form Create one from an existing image (ie Bitmap).
10/09/13
Author: Vaibhav, Reviewer: Prasanna
12
Fonts
Defines a particular format for a text, including font face, size and style attributes. This class can't be inherited. Constructor : Font(Font,Font Style) Font(Font Family,Single) Font(Font family,Single,Font Size)
Properties: Bold,Italic,Font Family,Size,Underline.
10/09/13
Author: Vaibhav, Reviewer: Prasanna
13
Graphics
Methods : DrawLine(); DrawRectangle(); DrawEclipse(); DrawArc(); etc.
10/09/13
Author: Vaibhav, Reviewer: Prasanna
14
Thank You!
10/09/13
Author: Vaibhav, Reviewer: Prasanna
15