Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 5 Graphics Erick Pranata. » Graphics Overview » About GDI+ » Getting Started.

Similar presentations


Presentation on theme: "Lecture 5 Graphics Erick Pranata. » Graphics Overview » About GDI+ » Getting Started."— Presentation transcript:

1 Lecture 5 Graphics Erick Pranata

2 » Graphics Overview » About GDI+ » Getting Started

3

4 » Successor of Graphic Device Interface » Responsible for displaying information on screens and printers » Namespaces: ˃System.Drawing ˃System.Drawing.Drawing2D ˃System.Drawing.Imaging ˃System.Drawing.Text ˃System.Drawing.Printing

5 » Two-dimensional (2-D) vector graphics ˃Lines, curves, etc. ˃Specified by set of points in coordinate system » Imaging ˃Bitmap » Typography

6 » Graphics Class ˃DrawLine receives a Pen object ˃FillRectangle receives a LinearGradientBrush object ˃Font and StringFormat ˃Rectangle, Point, Size ˃BitmapData

7 » Graphics Overview » About GDI+ » Getting Started

8

9

10 » Lines » Rectangles » Ellipses » Arcs » Polygons » Cardinal Splines » Bezier Splines

11 myGraphics.DrawRectangle( myPen, 20, 10, 100, 50 );

12 » Line ˃ myGraphics.DrawLine(myPen, 4, 2, 12, 6); ˃ Point myStartPoint = new Point(4, 2); Point myEndPoint = new Point(12, 6); myGraphics.DrawLine( myPen, myStartPoint, myEndPoint ); » Pen ˃ Pen myPen = new Pen(Color.Blue, 2); myGraphics.DrawLine( myPen, 0, 0, 60, 30 ); ˃ myPen.DashStyle = DashStyle.Dash; ˃StartCap and EndCap: +Square, Rounded, triangular, or custom shape

13 » Rectangle ˃ myGraphics.DrawRectangle( myPen, 100, 50, 80, 40 ); ˃ Rectangle myRectangle = new Rectangle(100, 50, 80, 40); myGraphics.DrawRectangle( myPen, myRectangle );

14 » Ellipse ˃ myGraphics.DrawEllipse(myPen, 100, 50, 80, 40); ˃ Rectangle myRectangle = new Rectangle(100, 50, 80, 40); myGraphics.DrawEllipse(myPen, myRectangle); » Arc ˃ myGraphics.DrawArc(myPen, 100, 50, 140, 70, 30, 180);

15 » Point[] myPointArray = { new Point(0, 0), new Point(50, 30), new Point(30, 60) }; myGraphics.DrawPolygon( myPen, myPointArray );

16 » myGraphics.DrawCurve(myPen, myPointArray, 1.5f);

17 » Spesified by four points: ˃Two end points ˃Two control points: act as magnets » myGraphics.DrawBezier(myPen, 0, 0, 40, 20, 80, 150, 100, 10);

18 » Combining vector graphics » Example: ˃ GraphicsPath myGraphicsPath = new GraphicsPath(); myGraphicsPath.AddLine(0, 0, 30, 20); myGraphicsPath.AddEllipse(20, 20, 20, 40); myGraphicsPath.AddBezier(30, 60, 70, 60, 50, 30, 100, 10); myGraphics.DrawPath(myPen, myGraphicsPath);

19 » Solid Brush ˃ SolidBrush mySolidBrush = new SolidBrush(Color.Red); myGraphics.FillEllipse( mySolidBrush, 0, 0, 60, 40 ); » Hatch Brush ˃ HatchBrush myHatchBrush = new HatchBrush( HatchStyle.Vertical, Color.Blue, Color.Green );

20 » Texture Brush ˃ Image myImage = Image.FromFile( "MyTexture.bmp“ ); TextureBrush myTextureBrush = new TextureBrush(myImage); » Gradient Brush ˃ LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush( myRectangle, Color.Blue, Color.Green, LinearGradientMode.Horizontal );

21 » myGraphics.FillRegion( mySolidBrush, myRegion);

22 » myGraphics.Clip = myRegion; myGraphics.DrawLine( myPen, 0, 0, 200, 200);

23 » myGraphics.SmoothingMode = SmoothingMode.AntiAlias;

24 » Graphics Overview » About GDI+ » Getting Started

25

26 » PaintEventArgs from Paint event ˃ private void Form1_Paint( object sender, System.Windows.Forms.PaintEventArgs pe ) { Graphics g = pe.Graphics; } » CreateGraphics of a component ˃ Graphics g = this.CreateGraphics(); » Create a Graphics object from an Image ˃ Bitmap myBitmap = new Bitmap("myPic.bmp"); Graphics g = Graphics.FromImage(myBitmap);

27 » Pen » Brush » Font » Color Do not forget to dispose them after use

28 » Use Invalidate() method ˃ this.Invalidate()

29 » string drawString = "Sample Text"; » Font drawFont = new Font("Arial", 16); » SolidBrush drawBrush = new SolidBrush(Color.Black); » StringFormat drawFormat = new StringFormat(); » myGraphics.DrawString( drawString, drawFont, drawBrush, 150, 50, drawFormat);

30

31 » MouseClick » MouseDoubleClick » MouseDown » MouseEnter » MouseHover » MouseLeave » MouseMove » MouseUp

32

33

34

35

36

37 » Graphics and Drawing in Windows Forms, http://msdn.microsoft.com/en- us/library/a36fascx(v=vs.110).aspxhttp://msdn.microsoft.com/en- us/library/a36fascx(v=vs.110).aspx


Download ppt "Lecture 5 Graphics Erick Pranata. » Graphics Overview » About GDI+ » Getting Started."

Similar presentations


Ads by Google