Graphics and Multimedia. OUTLINE Font Control Drawing Lines, Rectangles and Ovals Drawing Arcs Drawing a General Path.

Slides:



Advertisements
Similar presentations
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 30 - Dynamic HTML: Structured Graphics ActiveX Control Outline 30.1Introduction 30.2Shape Primitives.
Advertisements

Graphics Chapter 16.  If you want to draw shapes such as a bar chart, a clock, or a stop sign, how do you do it?
Chapter 9 Color, Sound and Graphics
COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
Graphics and Multimedia Session 13 Mata kuliah: M0874 – Programming II Tahun: 2010.
Java Graphics Section 1 - Multi-File Graphics Programs Section 2 - The Coordinate System and Graphics Context g Section 3 - The Java Drawing and Painting.
User Interface Programming in C#: Graphics
1 Graphics -- Introduction zThe use of graphics is common among modern software systems  Java has strong API support for graphics in the java.awt (abstract.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
1 Chapter 15 l Basic Figures l Colors l Fonts and Other Text Details Graphics Objects.
1 L37 Graphics and Java 2D™ (2). 2 OBJECTIVES To use methods of class Graphics to draw lines,  rectangles,  rectangles with rounded corners,  three-dimensional.
May 11, 1998CS102-02Lecture 7-1 More Graphics in Java CS Lecture 7-1 A picture's worth a thousand words.
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.
1 L38 Graphics and Java 2D™ (3). 2 OBJECTIVES In this chapter you will learn:  To understand graphics contexts and graphics objects.  To understand.
 2006 Pearson Education, Inc. All rights reserved Graphics and Multimedia.
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
Graphics and Multimedia. Outline Drawing Polygons and Polylines Advanced Graphics Capabilities.
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.
Lecture Set 13 Drawing Mouse and Keyboard Events Part A - Drawing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 26 – CheckWriter Application Introducing Graphics.
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.
Graphics and Multimedia Part #2
DHTML: Structured Graphics ActiveX Control
COM148X1 Interactive Programming Lecture 6. Topics Today Generate Random Numbers Graphics Animation.
Chapter 15 Graphics and Java 2D™ Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction.
Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction 28.2Graphics Contexts and Graphics Objects 28.3Color Control 28.4Font Control 28.5Drawing.
 Pearson Education, Inc. All rights reserved. 1 Ch 12 Graphics and Java 2D In this chapter you will learn:  To understand graphics contexts.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Chapter 15Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 15 l Basic Figures l Colors l Fonts and Other Text Details.
Introduction to Java Simple Graphics. Objects and Methods Recall that a method is an action which can be performed by an object. –The action takes place.
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.
Do Now: Please take out your notebook and a pen Ms. Edelman Technology Aim: How can I use type to express movement and rhythm?
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 19 – Dynamic HTML: Structured Graphics ActiveX Control Outline 19.1Introduction 19.2Shape.
Chapter 16 – Graphics and Multimedia. Outline 16.1Introduction 16.2 Graphics Contexts and Graphics Objects 16.3 Color Control 16.4 Font Control 16.5 Drawing.
GDI +. Graphics class's methods System.Drawing Graphics Objects.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Main characteristics of Vector graphics  Vector graphics provide an elegant way of constructing digital images (diagrams, technical illustration and.
Graphics Drawing Things With Java. Today's Topics Course Updates Java Graphics –Java 1.1 versus Java 1.2 (Java 2) Drawing Lines Drawing Shapes.
(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)
Graphics and Multimedia
12 Graphics and Java 2D™.
Lines, Curves, and Area Fill
Graphics and Multimedia
Computer Programming I
Graphics and Multimedia
JAVA 2 Design and programming of GUI
Drawing Mouse and Keyboard Events Part A - Drawing
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
ThS. Nguyễn Hà Giang Khoa CNTT - Hutech
CASE Tools Graphical User Interface Programming Using C#
Graphics -- Introduction
Repetition and Multiple Forms
Graphics and Multimedia
Chapter 12 Graphics in Windows and the Web
CPT 450 Computer Graphics 3rd Lecture.
Lines, Curves and Area Fills
Presentation transcript:

Graphics and Multimedia

OUTLINE Font Control Drawing Lines, Rectangles and Ovals Drawing Arcs Drawing a General Path

Font Control Font s – After a Font is created, its properties cannot be modified – Programmers must create a new Font object to be different Font constructors – Must require a font name as an argument – They usually require the font size as an argument – And usually require the font style which is a member of the FontStyle enumeration: Bold, Italic, Regular, Strikeout, Underline. Graphics method DrawString sets the current drawing font— the font in which the text displays—to its Font argument.

DrawString constructors: – takes a String to display, – the display Font, – a Brush – and the x- and y-coordinates of the location for the String’s first character. Font Control

GraphicsUnit argument—an enumeration that allows users to specify the unit of measurement employed to describe the font size. Members of the GraphicsUnit enumeration include Point (1/72 inch), Display (1/75 inch), Document (1/300 inch), Millimeter, Inch and Pixel.

1 ' Fig. 16.9: UsingFonts.vb 2 ' Demonstrating various font settings. 3 4 Public Class FrmFonts 5 Inherits System.Windows.Forms.Form 6 9 ' demonstrate various font and style settings 10 Protected Overrides Sub OnPaint( ByVal paintEvent As PaintEventArgs) Dim graphicsObject As Graphics = paintEvent.Graphics 14 Dim brush As SolidBrush = New SolidBrush(Color.DarkBlue) ' arial, 12 pt bold 17 Dim style As FontStyle = FontStyle.Bold 18 Dim arial As Font = New Font( New FontFamily("Arial"), 12, style) ' times new roman, 12 pt regular 22 style = FontStyle.Regular 23 Dim timesNewRoman As Font = New Font( "Times New Roman", 12, style) ' courier new, 16 pt bold and italic 27 style = FontStyle.Bold Or FontStyle.Italic 28 Dim courierNew As Font = New Font("Courier New", 16, style) 30 Creates a DarkBlue SolidBrush object ( brush ), causing all strings drawn with that brush to appear in DarkBlue

31 ' tahoma, 18 pt strikeout 32 style = FontStyle.Strikeout 33 Dim tahoma As Font = New Font("Tahoma", 18, style) graphicsObject.DrawString(arial.Name & " 12 point bold.", arial, brush, 10, 10) graphicsObject.DrawString(timesNewRoman.Name & _ 39 " 12 point plain.", timesNewRoman, brush, 10, 30) graphicsObject.DrawString(courierNew.Name & _ 42 " 16 point bold and italic.", courierNew, brush, 10, 54 ) graphicsObject.DrawString(tahoma.Name & _ 45 " 18 point strikeout.", tahoma, brush, 10, 75) 46 End Sub ' OnPaint End Class ' FrmFonts

Drawing Lines, Rectangles and Ovals Drawing shape outlines – Versions that take a Pen and four Integer s are used Drawing solid shapes – Versions that take a Brush and four Integer s Integer arguments – First two represent the coordinates of the upper-left corner of the shape or its enclosing area – Last two indicate the shape’s width and height

Drawing Lines, Rectangles and Ovals

Fig Ellipse bounded by a rectangle. height width (x, y)

1 ' Fig : LinesRectanglesOvals.vb 2 ' Demonstrating lines, rectangles, and ovals. 3 4 Public Class FrmDrawing 5 Inherits System.Windows.Forms.Form 6 7 ' Visual Studio.NET generated code 8 9 ' display ovals lines, and rectangles 10 Protected Overrides Sub OnPaint( _ 11 ByVal paintEvent As PaintEventArgs) ' get graphics object 14 Dim g As Graphics = paintEvent.Graphics 15 Dim brush As SolidBrush = New SolidBrush(Color.Blue) 16 Dim pen As Pen = New Pen(Color.AliceBlue) ' create filled rectangle 19 g.FillRectangle(brush, 90, 30, 150, 90) ' draw lines to connect rectangles 22 g.DrawLine(pen, 90, 30, 110, 40) 23 g.DrawLine(pen, 90, 120, 110, 130) 24 g.DrawLine(pen, 240, 30, 260, 40) 25 g.DrawLine(pen, 240, 120, 260, 130) ' draw top rectangle 28 g.DrawRectangle(pen, 110, 40, 150, 90) ' set brush to red 31 brush.Color = Color.Red ' draw base Ellipse 34 g.FillEllipse(brush, 280, 75, 100, 50) 35

36 ' draw connecting lines 37 g.DrawLine(pen, 380, 55, 380, 100) 38 g.DrawLine(pen, 280, 55, 280, 100) ' draw Ellipse outline 41 g.DrawEllipse(pen, 280, 30, 100, 50) 42 End Sub ' OnPaint End Class ' FrmDrawing

Drawing Arcs Arcs – Arcs are portions of ellipses. – Measured in degrees, beginning at the starting angle and continuing for a specified number of degrees, the arc angle. – An arc is said to sweep (traverse) its arc angle, beginning from its starting angle. – Measuring Sweep in a clockwise direction, measured in positive degrees Sweep in a counterclockwise direction, measured in negative degrees – Graphics methods used to draw arcs DrawArc, DrawPie, and FillPie

Drawing Arcs Fig Positive and negative arc angles.

Drawing Arcs

1 ' Fig : DrawArcs.vb 2 ' Drawing various arcs on a form. 3 4 Public Class FrmArcTest 5 Inherits System.Windows.Forms.Form 8 9 Protected Overrides Sub OnPaint( _ 10 ByVal paintEvent As PaintEventArgs) ' get graphics object 13 Dim graphicsObject As Graphics = paintEvent.Graphics 14 Dim rectangle1 As Rectangle = New Rectangle(15, 35, 80, 80) 15 Dim brush1 As SolidBrush = New SolidBrush(Color.FireBrick) 16 Dim pen1 As Pen = New Pen(brush1, 1) 17 Dim brush2 As SolidBrush = New SolidBrush(Color.DarkBlue) 18 Dim pen2 As Pen = New Pen(brush2, 1) ' start at 0 and sweep 360 degrees 21 graphicsObject.DrawRectangle(pen1, rectangle1) 22 graphicsObject.DrawArc(pen2, rectangle1, 0, 360) ' start at 0 and sweep 110 degrees 25 rectangle1.Location = New Point(100, 35) 26 graphicsObject.DrawRectangle(pen1, rectangle1) 27 graphicsObject.DrawArc(pen2, rectangle1, 0, 110) ' start at 0 and sweep -270 degrees 30 rectangle1.Location = New Point(185, 35) 31 graphicsObject.DrawRectangle(pen1, rectangle1) 32 graphicsObject.DrawArc(pen2, rectangle1, 0, -270) 33 Draws a rectangle and then an arc inside the rectangle Changes the location of the Rectangle by setting its Location property to a new Point

34 ' start at 0 and sweep 360 degrees 35 rectangle1.Location = New Point(15, 120) 36 rectangle1.Size = New Size(80, 40) 37 graphicsObject.DrawRectangle(pen1, rectangle1) 38 graphicsObject.FillPie(brush2, rectangle1, 0, 360) ' start at 270 and sweep -90 degrees 41 rectangle1.Location = New Point(100, 120) 42 graphicsObject.DrawRectangle(pen1, rectangle1) 43 graphicsObject.FillPie(brush2, rectangle1, 270, -90) ' start at 0 and sweep -270 degrees 46 rectangle1.Location = New Point(185, 120) 47 graphicsObject.DrawRectangle(pen1, rectangle1) 48 graphicsObject.FillPie(brush2, rectangle1, 0, -270) 49 End Sub ' OnPaint End Class ' FrmArcTest Sets the Size property to a new Size object

General path is a shape constructed from straight lines and complex curves. TranslateTransform is a graphics method to indicate that the origin of an object should be translated to the coordinates (X,Y). RotateTransform is a graphics method to move an object to the next position with a particular rotation angle in degree. How to use… Dim graphicsObject As Graphics = e.Graphics graphicsObject.TranslateTransform(X,Y) graphicsObject.RotateTransform(angle) Drawing a General Path

DrawStars.vb 1 ' Fig : DrawStars.vb 2 ' Using paths to draw stars on a form. 3 4 Imports System.Drawing.Drawing2D 5 6 Public Class FrmDrawStars 7 Inherits System.Windows.Forms.Form 8 9 ' Visual Studio.NET generated code ' create path and draw stars along it 12 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) 13 Dim graphicsObject As Graphics = e.Graphics 14 Dim i As Integer 15 Dim random As Random = New Random() 16 Dim brush As SolidBrush = _ 17 New SolidBrush(Color.DarkMagenta) ' x and y points of path 20 Dim xPoints As Integer() = _ 21 {55, 67, 109, 73, 83, 55, 27, 37, 1, 43} 22 Dim yPoints As Integer() = _ 23 {0, 36, 36, 54, 96, 72, 96, 54, 36, 36} ' create graphics path for star 26 Dim star As GraphicsPath = New GraphicsPath() ' translate origin to (150, 150) 29 graphicsObject.TranslateTransform(150, 150) ' create star from series of points 32 For i = 0 To 8 Step 2 33 star.AddLine(xPoints(i), yPoints(i), _ 34 xPoints(i + 1), yPoints(i + 1)) 35 Next Defines two Integer arrays, representing the x- and y- coordinates of the points in the star

36 37 ' close shape 38 star.CloseFigure() ' rotate origin and draw stars in random colors 41 For i = 1 To graphicsObject.RotateTransform(20) brush.Color = Color.FromArgb(random.Next(200, 255), _ 45 random.Next(255), random.Next(255), random.Next(255)) graphicsObject.FillPath(brush, star) 48 Next End Sub ' OnPaint End Class ' FrmDrawStars Uses GraphicsPath method CloseFigure to complete the shape Draws the star 18 times, rotating it around the origin Uses Graphics method RotateTransform to move to the next position on the form Graphics method FillPath draws a filled version of the star with the Brush created earlier