Graphics and Multimedia. Outline Drawing Polygons and Polylines Advanced Graphics Capabilities.

Slides:



Advertisements
Similar presentations
Computer Graphics Prof. Muhammad Saeed Dept. of Computer Science & IT Federal Urdu University of Arts, Sciences and Technology.
Advertisements

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.
Chapter 9 Color, Sound and Graphics
COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
CSC1401 Drawing in Java - 2. Reminder from last class How do you save your modified picture? String filename = …; Picture stevePicture = new Picture(filename);
Graphics and Multimedia Session 13 Mata kuliah: M0874 – Programming II Tahun: 2010.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
User Interface Programming in C#: Graphics
 2002 Prentice Hall. All rights reserved. 1 Chapter 16 – Graphics and Multimedia Outline 只教 Introduction 16.2 Graphics Contexts and Graphics.
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.
Events. Events Single Event Handlers Click Event Mouse Events Key Board Events Create and handle controls in runtime Outline.
Mouse draw Using the mouse and a palette to make a picture.
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
Chapter 13: Advanced GUI and Graphics
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
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,
Lecture Set 13 Drawing Mouse and Keyboard Events Part A - Drawing.
Graphics and Multimedia. Outline Introduction to Multimedia Loading, Displaying and Scaling Images Windows Media Player Adding a Flash Movie Microsoft.
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.
 2002 Prentice Hall. All rights reserved. 1 Chapter 16 – Graphics and Media Outline 16.1 Introduction 16.2 Graphics Contexts and Graphics Objects 16.3.
Object Oriented Programming Graphics and Multimedia Dr. Mike Spann
C# Programming Lecture 4 “GDI+” PGL01/CSP/2006.
Graphics and Multimedia Part #2
COM148X1 Interactive Programming Lecture 6. Topics Today Generate Random Numbers Graphics Animation.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Screen Saver Application.
Visual Basic .NET BASICS
Chapter 15 Graphics and Java 2D™ Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction 28.2Graphics Contexts and Graphics Objects 28.3Color Control 28.4Font Control 28.5Drawing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Lecture 5 Graphics Erick Pranata. » Graphics Overview » About GDI+ » Getting Started.
Tkinter Canvas.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
(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.
16.9 Introduction to Multimedia Visual Basic offers many convenient ways to include images and animations in programs Computing field decades ago mainly.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
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.
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.
Lab 10 Slides.
Windows Programming C# Software Development. Overview  DLLs / PInvoke  DirectX .NET Component Library  Custom Controls  Event Model (in C++)  GUI.
Paint Tutorial Created February 2006 Start Paint: Start>Programs>Accessories>Paint.
(PART III) Graphics and Multimedia 16/02/1437 Lect6 CT
GDI +. Graphics class's methods System.Drawing Graphics Objects.
(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™.
Graphics and Multimedia
Computer Programming I
Graphics and Multimedia
JAVA 2 Design and programming of GUI
Drawing Mouse and Keyboard Events Part A - Drawing
ThS. Nguyễn Hà Giang Khoa CNTT - Hutech
CASE Tools Graphical User Interface Programming Using C#
Graphics and Multimedia
Lecture 9 GUI and Event Driven CSE /16/2019.
Object Oriented Programming
Graphics and Multimedia
Chapter 12 Graphics in Windows and the Web
CPT 450 Computer Graphics 3rd Lecture.
Presentation transcript:

Graphics and Multimedia

Outline Drawing Polygons and Polylines Advanced Graphics Capabilities

Drawing Polygons and Polylines Polygons – Multisided shapes – Graphics methods used to draw polygons DrawLines, DrawPolygon, and FillPolygon

Drawing Polygons and Polylines

1 ' Fig : DrawPolygons.vb 2 ' Demonstrating polygons. 3 4 Public Class FrmPolygon 5 Inherits System.Windows.Forms.Form 6 21 ' contains list of polygon points 22 Private mPoints As ArrayList = New ArrayList() ' initialize default pen and brush 25 Dim mPen As Pen = New Pen(Color.DarkBlue) 26 Dim mBrush As SolidBrush = New SolidBrush(Color.DarkBlue) ' draw panel mouse down event handler 29 Private Sub drawWindow_MouseDown(ByVal sender _ 30 As Object, ByVal e As _ 31 System.Windows.Forms.MouseEventArgs) _ 32 Handles drawWindow.MouseDown ' Add mouse position to vertex list 35 mPoints.Add(New Point(e.X, e.Y)) 36 drawWindow.Invalidate() ' refresh panel 37 End Sub ' drawWindow_MouseDown ' draw panel paint event handler 40 Private Sub drawWindow_Paint(ByVal sender As Object, _ 41 ByVal e As System.Windows.Forms.PaintEventArgs) _ 42 Handles drawWindow.Paint ' get graphics object for panel 45 Dim graphicsObject As Graphics = e.Graphics Declaring ArrayList mPoints as a container for our Point objects allows the user to specify a variable number of points The MouseDown event handler for Panel drawWindow stores mouse-click locations in the mPoints ArrayList. Calls method Invalidate of drawWindow to ensure that the panel refreshes to accommodate the new point. if the ArrayList mPoints contains two or more Points, displays the polygon using the method that the user selected via the GUI radio buttons

46 47 ' if arraylist has 2 or more points, display shape 48 If mPoints.Count > 1 Then ' get array for use in drawing functions 51 Dim pointArray() As Point = _ 52 mPoints.ToArray(mPoints(0).GetType()) If polygonRadio.Checked Then ' draw polygon 55 graphicsObject.DrawPolygon(mPen, pointArray) ElseIf lineRadio.Checked Then ' draw lines 58 graphicsObject.DrawLines(mPen, pointArray) ElseIf filledPolygonRadio.Checked Then ' draw filled 61 graphicsObject.FillPolygon(mBrush, pointArray) 62 End If End If End Sub ' drawWindow_Paint ' handle cmdClear click event 69 Private Sub cmdClear_Click(ByVal sender As System.Object, _ 70 ByVal e As System.EventArgs) Handles cmdClear.Click mPoints = New ArrayList() ' remove points drawWindow.Invalidate() ' refresh panel 75 End Sub ' cmdClear_Click Extracts an Array from the ArrayList via method ToArray Method ToArray can take a single argument to determine the type of the returned array; we obtain the type from the first element in the ArrayList. Creates an empty ArrayList (causing the old list to be erased) and refreshes the display.

76 77 ' handle polygon radio button CheckedChange event 78 Private Sub polygonRadio_CheckedChanged(ByVal sender As _ 79 System.Object, ByVal e As System.EventArgs) _ 80 Handles polygonRadio.CheckedChanged drawWindow.Invalidate() ' refresh panel 83 End Sub ' polygonRadio_CheckedChanged ' handle line radio button CheckChanged event 86 Private Sub lineRadio_CheckedChanged(ByVal sender As _ 87 System.Object, ByVal e As System.EventArgs) _ 88 Handles lineRadio.CheckedChanged drawWindow.Invalidate() ' refresh panel 91 End Sub ' lineRadio_CheckedChanged ' handle filled polygon radio button CheckChanged event 94 Private Sub filledPolygonRadio_CheckedChanged(ByVal sender _ 95 As System.Object, ByVal e As System.EventArgs) _ 96 Handles filledPolygonRadio.CheckedChanged drawWindow.Invalidate() ' refresh panel 99 End Sub ' filledPolygonRadio_CheckedChanged 100 Lines 78–++ define the event handlers for the radio buttons’ CheckedChanged event. Each method refreshes Panel drawWindow to ensure that the panel display reflects the selected drawing type.

101 ' handle cmdNewColor click event 102 Private Sub cmdNewColor_Click(ByVal sender As _ 103 System.Object, ByVal e As System.EventArgs) _ 104 Handles cmdNewColor.Click ' create new color dialog 107 Dim colorBox As ColorDialog = New ColorDialog() ' show dialog and obtain result 110 Dim result As DialogResult = colorBox.ShowDialog() ' return if user cancels 113 If result = DialogResult.Cancel Then 114 Return 115 End If mPen.Color = colorBox.Color ' set pen to new color 118 mBrush.Color = colorBox.Color ' set brush 119 drawWindow.Invalidate() ' refresh panel 120 End Sub ' cmdNewColor_Click End Class ' FrmPolygon Event method cmlNewColor_Click allows the user to select a new drawing color with a ColorDialog

Advanced Graphics Capabilities Visual Basic offers many additional graphics capabilities Examples – Brush hierarchy also includes: HatchBrush, LinearGradientBrush, PathGradientBrush and TextureBrush – Additional graphics features Dashed lines, thick lines, filling shapes with patterns, etc

Bitmap Class Produce images in color and gray scale with a particular width and height. Used to work with images defined by pixel data. How to use… Dim graphicsObject As Graphics = e.Graphics Dim BitmapVar As Bitmap = New Bitmap(width, height). Dim BrushVar As TextureBrush = New TextureBrush(BitmapVar) graphicsObject.FillRectangle(BrushVar, X, Y, width, height) Advanced Graphics Capabilities

DrawShapes.vb 1 ' Fig : DrawShapes.vb 2 ' Drawing various shapes on a form. 3 4 Imports System.Drawing.Drawing2D 5 6 Public Class FrmDrawShapes 7 Inherits System.Windows.Forms.Form 8 9 ' Visual Studio.NET generated code ' draw various shapes on form 12 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) ' references to object we will use 15 Dim graphicsObject As Graphics = e.Graphics ' ellipse rectangle and gradient brush 18 Dim drawArea1 As Rectangle = New Rectangle(5, 35, 30, 100) 19 Dim linearBrush As LinearGradientBrush = _ 20 New LinearGradientBrush(drawArea1, Color.Blue, _ 21 Color.Yellow, LinearGradientMode.ForwardDiagonal) ' pen and location for red outline rectangle 24 Dim thickRedPen As Pen = New Pen(Color.Red, 10) 25 Dim drawArea2 As Rectangle = New Rectangle(80, 30, 65, 100) ' bitmap texture 28 Dim textureBitmap As Bitmap = New Bitmap(10, 10) 29 Dim graphicsObject2 As Graphics = _ 30 Graphics.FromImage(textureBitmap) ' get bitmap graphics ' brush and pen used throughout program 33 Dim solidColorBrush As SolidBrush = _ 34 New SolidBrush(Color.Red) 35 Dim coloredPen As Pen = New Pen(solidColorBrush) Creates a Pen object pen, and passes arguments Color.Red and Integer 10, indicating that we want pen to draw red lines that are 10 pixels wide Creates a new Bitmap image, which is initially empty retrieves the Graphics object associated with an Image, which may be used to draw on an image.

DrawShapes.vb ' draw ellipse filled with a blue-yellow gradient 38 graphicsObject.FillEllipse(linearBrush, 5, 30, 65, 100) ' draw thick rectangle outline in red 41 graphicsObject.DrawRectangle(thickRedPen, drawArea2) ' fill textureBitmap with yellow 44 solidColorBrush.Color = Color.Yellow 45 graphicsObject2.FillRectangle(solidColorBrush, 0, 0, 10, 10) ' draw small black rectangle in textureBitmap 48 coloredPen.Color = Color.Black 49 graphicsObject2.DrawRectangle(coloredPen, 1, 1, 6, 6) ' draw small blue rectangle in textureBitmap 52 solidColorBrush.Color = Color.Blue 53 graphicsObject2.FillRectangle(solidColorBrush, 1, 1, 3, 3) ' draw small red square in textureBitmap 56 solidColorBrush.Color = Color.Red 57 graphicsObject2.FillRectangle(solidColorBrush, 4, 4, 3, 3) ' create textured brush and display textured rectangle 60 Dim texturedBrush As TextureBrush = _ 61 New TextureBrush(textureBitmap) graphicsObject.FillRectangle( _ 64 texturedBrush, 155, 30, 75, 100) ' draw pie-shaped arc in white 67 coloredPen.Color = Color.White 68 coloredPen.Width = 6 69 graphicsObject.DrawPie( _ 70 coloredPen, 240, 30, 75, 100, 0, 270) A TextureBrush is a brush that fills the interior of a shape with an image, rather than a solid color. draw on the Bitmap a pattern consisting of black, blue, red and yellow rectangles and lines.

71 72 ' draw lines in green and yellow 73 coloredPen.Color = Color.Green 74 coloredPen.Width = 5 75 graphicsObject.DrawLine(coloredPen, 395, 30, 320, 150) ' draw a rounded, dashed yellow line 78 coloredPen.Color = Color.Yellow 79 coloredPen.DashCap = LineCap.Round 80 coloredPen.DashStyle = DashStyle.Dash 81 graphicsObject.DrawLine(coloredPen, 320, 30, 395, 150) 82 End Sub ' OnPaint End Class ' FrmDrawShapes The DashCap enumeration specifies the styles for the start and end of a dashed line.