GDI +. Graphics class's methods System.Drawing Graphics Objects.

Slides:



Advertisements
Similar presentations
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Advertisements

User Interface Programming in C#: Graphics
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Topics  Applets  Classes used for graphics Graphics Point Dimension.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
Chapter 13 Graphics, Animation, Sound, and Drag-and-Drop Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Java Graphics Applets.
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
Graphics and Multimedia. Outline Drawing Polygons and Polylines Advanced Graphics Capabilities.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Računarska grafika GDI+ (Graphics Device Interface Plus)
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
Graphics Images – PictureBox control Drawing graphics - Graphics object Multimedia controls PictureBox control Image property – select image Choose how.
1 Chapter 26 D&D – Graphics Outline 26.1 Introduction 26.3 Graphics Contexts and Graphics Objects 26.4 Color Control 26.5 Font Control 26.6 Drawing Lines,
CS324e - Elements of Graphics and Visualization Java2D Graphics.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface A Brief Introduction to GDI+ S.R.G. Fraser, Pro Visual C++/CLI.
CST238 Week 5 Questions / Concerns? Announcements – HW#1 due (Project ideas) – Check-off Take Home lab#4 Recap New topics – Drawing Coming up: – GUI Bloopers.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 26 – CheckWriter Application Introducing Graphics.
1 Windows Graphics. 2 Objectives You will be able to Use the Windows GDI+ to draw arbitrary figures and text on a Windows form. Add a handler for the.
Java Software Solutions Lewis and Loftus Chapter 7 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphics -- Introduction The.
1 Graphical User Components (II) Outline JTextArea Creating a Customized Subclass of JPanel JPanel Subclass that Handles Its Own Events Windows: Additional.
Object Oriented Programming Graphics and Multimedia Dr. Mike Spann
C# Programming Lecture 4 “GDI+” PGL01/CSP/2006.
Graphics and Multimedia Part #2
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
Chapter 7 Graphics. © Daly and Wrigley Objectives Use Graphic Components: ▫ Strings ▫ Lines ▫ Rectangles ▫ Ovals ▫ Arcs Change the color and font of elements.
GDI+ 1. Objectives 2 GDI+ class  Create and render Graphic  Display information on the computer screen, printer 3.
Canvas and Graphics CS 21a. 9/26/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L17: Canvas.
Applets Applet is java program that can be embedded into HTML pages. Java applets runs on the java enabled web browsers such as mozilla and internet explorer.
Graphics Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data.
Lecture 5 Graphics Erick Pranata. » Graphics Overview » About GDI+ » Getting Started.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Tkinter Canvas.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
1 Graphic Device Interface (GDI). 2 Class Form A Form is a representation of any window displayed in your application. The Form class can be used to create.
Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics ikt403 – Object-Oriented Software Development.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
CSI 3125, Preliminaries, page 1 AWT. CSI 3125, Preliminaries, page 2 AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based.
Graphics and Multimedia. OUTLINE Font Control Drawing Lines, Rectangles and Ovals Drawing Arcs Drawing a General Path.
Images Part 11 dbg. 2 Images The form and several controls can display a number of different types of image files in the BackgroundImage Property. These.
Windows Programming C# Software Development. Overview  DLLs / PInvoke  DirectX .NET Component Library  Custom Controls  Event Model (in C++)  GUI.
V 1.0 Programming III. Graphical possibilities Simple graphics (shapes)
(PART III) Graphics and Multimedia 16/02/1437 Lect6 CT
6.1 Coordinates The screen of a computer is a grid of little squares called pixels. The color of each pixel can be set individually, and drawing on the.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
(PART II) Graphics and Multimedia. Font Control Font s  After a Font is created, its properties cannot be modified  Programmers must create a new Font.
Graphics and Multimedia 2 Lecture 8. OUTLINE Font Control Drawing Lines, Rectangles and Ovals Drawing a General Path.
(PART II) Graphics and Multimedia 11/02/1437 Lect6 (Part 2)
Programming windows with MFC Chapter 2 - Drawing in a Window
Chapter 8 Graphics.
Lines, Curves, and Area Fill
Graphics.
Graphics and Multimedia
Graphics and Multimedia
Chapter 10 Graphics.
ThS. Nguyễn Hà Giang Khoa CNTT - Hutech
CASE Tools Graphical User Interface Programming Using C#
Graphics and Multimedia
Repetition and Multiple Forms
Chapter 8 Graphics.
Graphics and Multimedia
Chapter 12 Graphics in Windows and the Web
Chapter 14 Drawing in a Window
Chapter 16 Drawing in a Window
CPT 450 Computer Graphics 3rd Lecture.
Lines, Curves and Area Fills
Presentation transcript:

GDI +

Graphics class's methods System.Drawing

Graphics Objects

The Pen Class A pen draws a line of specified width and style. You always use Pen constructor to create a pen. The constructor initializes a new instance of the Pen class. You can initialize it with a color or brush. Initializes a new instance of the Pen class with the specified color. public Pen(Color); Initializes a new instance of the Pen class with the specified Brush. public Pen(Brush); Initializes a new instance of the Pen class with the specified Brush and width. public Pen(Brush, float); Initializes a new instance of the Pen class with the specified Color and Width. public Pen(Color, float); Here is one example: Pen pn = new Pen( Color.Blue ); or Pen pn = new Pen( Color.Blue, 100 ); Some of its most commonly used properties are: Align ment Gets or sets the alignment for objects drawn with this Pen. BrushGets or sets the Brush that determines attributes of this Pen. ColorGets or sets the color of this Pen. WidthGets or sets the width of this Pen.

Graphics Class private void form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; } OR protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; }

The Color Structure A Color structure represents an ARGB color. Here are ARGB properties of it: AGets the alpha component value for this Color. BGets the blue component value for this Color. GGets the green component value for this Color. RGets the red component value for this Color. You can call the Color members. Each color name (say Blue) is a member of the Color structure. Here is how to use a Color structure: Pen pn = new Pen( Color.Blue );

The Font Class The Font class defines a particular format for text such as font type, size, and style attributes. You use font constructor to create a font. Initializes a new instance of the Font class with the specified attributes. public Font(string, float); Initializes a new instance of the Font class from the specified existing Font and FontStyle. public Font(Font, FontStyle); Where FontStyle is an enumeration and here are its members: Member Name Description BoldBold text. ItalicItalic text. RegularNormal text. Strikeou t Text with a line through the middle. Underlin e Underlined text.

Here is one example: Graphics g ; Font font = new Font("Times New Roman", 26); Some of its most commonly used properties are: BoldGets a value indicating whether this Font is bold. FontFamilyGets the FontFamily of this Font. HeightGets the height of this Font. ItalicGets a value indicating whether this Font is Italic. NameGets the face name of this Font. SizeGets the size of this Font. SizeInPointsGets the size, in points, of this Font. StrikeoutGets a value indicating whether this Font is strikeout (has a line through it). StyleGets style information for this Font. UnderlineGets a value indicating whether this Font is underlined. UnitGets the unit of measure for this Font.

The Brush Class The Brush class is an abstract base class and cannot be instantiated. We always use its derived classes to instantiate a brush object, such as SolidBrush, TextureBrush, RectangleGradientBrush, and LinearGradientBrush. Here is one example: LinearGradientBrush lBrush = new LinearGradientBrush(rect, Color.Red, Color.Yellow, LinearGradientMode.BackwardDiagonal); OR Brush brsh = new SolidBrush(Color.Red), 40, 40, 140, 140); The SolidBrush class defines a brush made up of a single color. Brushes are used to fill graphics shapes such as rectangles, ellipses, pies, polygons, and paths. The TextureBrush encapsulates a Brush that uses an fills the interior of a shape with an image. The LinearGradiantBrush encapsulates both two-color gradients and custom multi-color gradients.

The Rectangle Structure public Rectangle(Point, Size); or public Rectangle(int, int, int, int); The Rectangle structure is used to draw a rectangle on WinForms. Besides its constructor, the Rectangle structure has following members: BottomGets the y-coordinate of the lower-right corner of the rectangular region defined by this Rectangle. HeightGets or sets the width of the rectangular region defined by this Rectangle. IsEmptyTests whether this Rectangle has a Width or a Height of 0. LeftGets the x-coordinate of the upper-left corner of the rectangular region defined by this Rectangle. LocationGets or sets the coordinates of the upper-left corner of the rectangular region represented by this Rectangle. RightGets the x-coordinate of the lower-right corner of the rectangular region defined by this Rectangle. SizeGets or sets the size of this Rectangle. TopGets the y-coordinate of the upper-left corner of the rectangular region defined by this Rectangle. WidthGets or sets the width of the rectangular region defined by this Rectangle. XGets or sets the x-coordinate of the upper-left corner of the rectangular region defined by this Rectangle. YGets or sets the y-coordinate of the upper-left corner of the rectangular region defined by this Rectangle.

The Point Structure This structure is similar to the POINT structure in C++. t represents an ordered pair of x and y coordinates that define a point in a two-dimensional plane. The member x represents the x coordinates and y represents the y coordinates of the plane. Here is how to instantiate a point structure: Point pt1 = new Point( 30, 30); Point pt2 = new Point( 110, 100);

координати 1 единица = 1 пиксел Дисплейна повърхност +x+x +y+y (0,0) MM_TEXT +x+x +y+y (0,0) CenterPoint().x CenterPoint().y

Pen PS_SOLID PS_DASH PS_DOT PS_DASHDOT PS_DASHDOTDOT PS_NULL PS_INSIDEFRAME

Brush HS_BDIAGONAL HS_CROSS HS_DIAGCROSS HS_FDIAGONAL HS_HORIZONTAL HS_VERTICAL Стилове щриховки

Drawing a rectangle You can override OnPaint event of your form to draw an rectangle. The LinearGradientBrush encapsulates a brush and linear gradient. protected override void OnPaint(PaintEventArgs pe) { Graphics g = pe.Graphics ; Rectangle rect = new Rectangle(50, 30, 100, 100); LinearGradientBrush lBrush = new LinearGradientBrush(rect, Color.Red, Color.Yellow, LinearGradientMode.BackwardDiagonal); g.FillRectangle(lBrush, rect); }

Drawing an Arc DrawArc function draws an arc. This function takes four arguments. First is the Pen. You create a pen by using the Pen class. The Pen constructor takes at least one argument, the color or the brush of the pen. Second argument width of the pen or brush is optional. Pen pn = new Pen( Color.Blue ); or Pen pn = new Pen( Color.Blue, 100 ); The second argument is a rectangle. You can create a rectangle by using Rectangle structure. The Rectangle constructor takes four int type arguments and they are left and right corners of the rectangle. Rectangle rect = new Rectangle(50, 50, 200, 100); protected override void OnPaint(PaintEventArgs pe) { Graphics g = pe.Graphics ; Pen pn = new Pen( Color.Blue ); Rectangle rect = new Rectangle(50, 50, 200, 100); g.DrawArc( pn, rect, 12, 84 ); }

Drawing a Line DrawLine function of the Graphics class draws a line. It takes three parameters, a pen, and two Point class parameters, starting and ending points. Point class constructor takes x, y arguments. protected override void OnPaint(PaintEventArgs pe) { Graphics g = pe.Graphics ; Pen pn = new Pen( Color.Blue ); // Rectangle rect = new Rectangle(50, 50, 200, 100); Point pt1 = new Point( 30, 30); Point pt2 = new Point( 110, 100); g.DrawLine( pn, pt1, pt2 ); }

Drawing an Ellipse An ellipse( or a circle) can be drawn by using DrawEllipse method. This method takes only two parameters, Pen and rectangle. protected override void OnPaint(PaintEventArgs pe) { Graphics g = pe.Graphics ; Pen pn = new Pen( Color.Blue, 100 ); Rectangle rect = new Rectangle(50, 50, 200, 100); g.DrawEllipse( pn, rect ); }

The FillPath Drawing bazier curves is little more complex than other objects. protected override void OnPaint(PaintEventArgs pe) { Graphics g = pe.Graphics; g.FillRectangle(new SolidBrush(Color.White), ClientRectangle); GraphicsPath path = new GraphicsPath(new Point[] { new Point(40, 140), new Point(275, 200), new Point(105, 225), new Point(190, 300), new Point(50, 350), new Point(20, 180), }, new byte[] { (byte)PathPointType.Start, (byte)PathPointType.Bezier, (byte)PathPointType.Bezier, (byte)PathPointType.Bezier, (byte)PathPointType.Line, (byte)PathPointType.Line, }); PathGradientBrush pgb = new PathGradientBrush(path); pgb.SurroundColors = new Color[] { Color.Green,Color.Yellow,Color.Red, Color.Blue, Color.Orange, Color.White, }; g.FillPath(pgb, path); }

Drawing Text and Strings You can override OnPaint event of your form to draw an rectangle. The LinearGradientBrush encapsulates a brush and linear gradient. protected override void OnPaint(PaintEventArgs pe) { Font fnt = new Font("Verdana", 16); Graphics g = pe.Graphics; g.DrawString("GDI+ World", fnt, new SolidBrush(Color.Red), 14,10); }