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,

Slides:



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

Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
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?
Cosc 5/4730 Blackberry Drawing. Screen size With Blackberry devices, they have a known screen size in pixels. If you are programming for specific device.
Chapter 9 Color, Sound and Graphics
COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
More Java Drawing in 2D Animations with Timer. Drawing Review A simple two-dimensional coordinate system exists for each graphics context or drawing surface.
Graphics and Multimedia Session 13 Mata kuliah: M0874 – Programming II Tahun: 2010.
User Interface Programming in C#: Graphics
1 L36 Graphics and Java 2D™ (1). 2 OBJECTIVES  To understand graphics contexts and graphics objects.  To understand and be able to manipulate colors.
.NET Class 4 – Windows-based Application. WinForm Application Homogeny programming model. Rich class library Classes are shared by all.NET languages.
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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Applets and Graphics.
 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.
Copyright © 2012 Pearson Education, Inc. Chapter 2 Introduction to Visual C#
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.
Graphics and Multimedia In visual Studio. Net (C#)
Lecture Set 13 Drawing Mouse and Keyboard Events Part A - Drawing.
1 Interface Types & Polymorphism & introduction to graphics programming in Java.
1 Graphical User Interfaces Part 2 Outline Multiple Document Interface (MDI) Windows Visual Inheritance User-Defined Controls.
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.
 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.
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.
CSC 298 Windows Forms.
Graphics and Multimedia Part #2
Animation and Double-Buffering. The animation methods described here are based on standard techniques of double-buffering applicable to most high-level.
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.
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.
McGraw-Hill © 2010 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 13 Graphics, Animation, Sound and Drag-and-Drop.
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.
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 Concepts CS 2302, Fall /17/20142 Drawing in Android.
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.
Windows Programming C# Software Development. Overview  DLLs / PInvoke  DirectX .NET Component Library  Custom Controls  Event Model (in C++)  GUI.
 2002 Prentice Hall. All rights reserved. 1 Outline Mouse Event Handling Keyboard Event Handling Graphical User Interface Concepts:
(PART III) Graphics and Multimedia 16/02/1437 Lect6 CT
GDI +. Graphics class's methods System.Drawing Graphics Objects.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
Graphics and Multimedia 2 Lecture 8. OUTLINE Font Control Drawing Lines, Rectangles and Ovals Drawing a General Path.
Graphics and Multimedia
Graphics and Multimedia
Computer Programming I
Graphics and Multimedia
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 -- Introduction
Graphics and Multimedia
Object Oriented Programming
Chapter 12 Graphics in Windows and the Web
Presentation transcript:

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, Rectangles and Ovals 26.8 Drawing Polygons and Polylines Loading, Displaying and Scaling Images Animating a Series of Images

Introduction Graphical Device Interface –Two dimensional vector graphics Drawing capabilities –Pen or Brush object –Structure Color –Positioning in x,y coordinate system

Introduction Fig System.Drawing namespace’s classes and structures. structure class key System.Drawing Font FontFamily Graphics Icon Pen Region SolidBrush TextureBrush Image Brush HatchBrush LinearGradientBrush PathGradientBrush SolidBrush TextureBrush Color Point Rectangle Size

Graphics Contexts and Graphics Objects Fig. 26.2GDI+ coordinate system. Units are measured in pixels. x-axis y-axis (0, 0) +x +y (x, y)

Graphics Contexts and Graphics Objects Graphics context –Drawing surface Graphics object –control how information is drawn –Virtual OnPaint event handler –Method Invalidate Refreshes and repaints

Color Control Enhancing program appearance –Structure Color ARGB values Value range from 0 to 255 Run UsingColors.cs

ColorDialog // Create ColorDialog object private static ColorDialog myColorChooser = new ColorDialog(); //get chosen color DialogResult result = myColorChooser.ShowDialog(); if (result != DialogResult.Cancel) { // assign something’s color to result of dialog something’s color = myColorChooser.Color; } Demo UsingComplexColors 7

Font Control Methods and constants of font control –Creating Font Font’s metrics: –height, decent, ascent and leading Once created properties cannot be modified –Size property Return font size measured in design units xy1 Õ descent baseline ascent leading height Fig An illustration of font metrics.

Drawing Shapes: Lines, Rectangles and Ovals Graphics methods –Use for drawing lines, rectangles and ovals Shape outlines take Pen Solid shapes take Brush Int argument represent coordinates Last two int argument are for width and height Fig Ellipse bounded by a rectangle. (x, y) height width

Drawing Lines, Rectangles, and Ovals

11 LinesRectanglesO vals.cs 1 // Fig : LinesRectanglesOvals.cs 2 // Demonstrating lines, rectangles and ovals. 3 4 using System; 5 using System.Drawing; 6 using System.Collections; 7 using System.ComponentModel; 8 using System.Windows.Forms; 9 using System.Data; // draws shapes on the Form 12 public partial class LinesRectanglesOvals : Form 13 { 26 public LinesRectanglesOvals () 18 { 19 InitializeComponent(); 20 } 24 protected override void OnPaint( 25 PaintEventArgs paintEvent ) 26 { 27 // get graphics object 28 Graphics g = paintEvent.Graphics; 29 SolidBrush brush = new SolidBrush( Color.Blue ); 30 Pen pen = new Pen( Color.AliceBlue ); // create filled rectangle 33 g.FillRectangle( brush, 90, 30, 150, 90 ); 34 Drawing rectangle on the screen Drawing objectCoordinates for bounding rectangle Rectangle’s width and height

12 LinesRectanglesO vals.cs Program Output 35 // draw lines to connect rectangles 36 g.DrawLine( pen, 90, 30, 110, 40 ); 37 g.DrawLine( pen, 90, 120, 110, 130 ); 38 g.DrawLine( pen, 240, 30, 260, 40 ); 39 g.DrawLine( pen, 240, 120, 260, 130 ); // draw top rectangle 42 g.DrawRectangle( pen, 110, 40, 150, 90 ); // set brush to red 45 brush.Color = Color.Red; // draw base Ellipse 48 g.FillEllipse( brush, 280, 75, 100, 50 ); // draw connecting lines 51 g.DrawLine( pen, 380, 55, 380, 100 ); 52 g.DrawLine( pen, 280, 55, 280, 100 ); // draw Ellipse outline 55 g.DrawEllipse( pen, 280, 30, 100, 50 ); } // end method OnPaint } // end class LinesRectanglesOvals DrawLine takes a Pen and two pairs of ints Start and end point of the line Uses pen object to draw Overloaded methods DrawEllipse and FillEllipse Specify drawing objectCoordinates of the bounding rectangle for the ellipse Bounding rectangle’s width and height

Drawing Polygons and Polylines Polygons –Multisided shapes –DrawLines Series of connected points –DrawPolygon Closed polygon –FillPolygon Solid polygon

Drawing Polygons and Polylines

15 DrawPolygons.cs Program Output

Loading, Displaying and Scaling Images C#’s multimedia capabilities –Graphics –Images –Animations –video

17 DisplayLogoForm. cs

18 DisplayLogoForm. cs 1 // Fig : DisplayLogoForm.cs 2 // Displaying and resizing an image. 3 4 using System; 5 using System.Drawing; 6 using System.Collections; 7 using System.ComponentModel; 8 using System.Windows.Forms; 9 using System.Data; 14 private System.Windows.Forms.Button setButton; 15 private System.Windows.Forms.TextBox heightTextBox; 16 private System.Windows.Forms.Label heightLabel; 26 private System.Windows.Forms.TextBox widthTextBox; 18 private System.Windows.Forms.Label widthLabel; // displays an image and allows the user to resize it 12 public partial class DisplayLogoForm : Form 13 { 23 private Image image = Image.FromFile( "images/Logo.gif" ); 25 private Graphics graphicsObject; public DisplayLogoForm() 28 { 29 InitializeComponent(); graphicsObject = this.CreateGraphics(); 32 } 33 image is assign through method FromFile Method CreateGraphics to create a Graphics object associated with the Form

19 DisplayLogoForm. cs 42 private void setButton_Click( 43 object sender, System.EventArgs e ) 44 { 45 // get user input 46 int width = Convert.ToInt32( widthTextBox.Text ); 47 int height = Convert.ToInt32( heightTextBox.Text ); // if dimensions specified are too large 50 // display problem 51 if ( width > 375 || height > 225 ) 52 { 53 MessageBox.Show( "Height or Width too large" ); return; 56 } // clear Windows Form 59 graphicsObject.Clear( this.BackColor ); // draw image 62 graphicsObject.DrawImage( 63 image, 5, 5, width, height ); } // end method setButton_Click } // end class DisplayLogoForm When user select Set, test to validate they are in acceptable range Method Clear to paint entire Form in current background color Graphics method DrawImage is called to display image

Animating a Series of Images Animate series of images from an array Collision detection Regional invalidation

21 LogoAnimator.cs 1 // Fig : LogoAnimator.cs 2 // Program that animates a series of images. 3 4 using System; 5 using System.Drawing; 6 using System.Collections; 7 using System.ComponentModel; 8 using System.Windows.Forms; 9 using System.Data; private System.Windows.Forms.PictureBox logoPictureBox; 15 private System.Windows.Forms.Timer Timer; 16 private System.ComponentModel.IContainer components; 11 // animates a series of 30 images 12 public private class LogoAnimator : Form 13{ 18 private ArrayList images = new ArrayList(); 19 private int count = -1; public LogoAnimator() 22 { 23 InitializeComponent(); for ( int i = 0; i < 30; i++ ) 26 images.Add( Image.FromFile( "images/deitel" + i + 27 ".gif" ) ); // load first image 30 logoPictureBox.Image = ( Image ) images[ 0 ]; // set PictureBox to be the same size as Image 33 logoPictureBox.Size = logoPictureBox.Image.Size; } // end constructor PictureBox contain images to animate Timer to cycle through the image Count keeps track of current image Load each of 30 images and store in an ArrayList Places first image in the PictureBox Modify size if PictureBox to equal size of Image

22 45 private void Timer_Tick( 46 object sender, System.EventArgs e ) 47 { 48 // increment counter 49 count = ( count + 1 ) % 30; // load next image 52 logoPictureBox.Image = ( Image )images[count ]; } // end method Timer_Tick } // end class LogoAnimator LogoAnimator.cs Program Output