Graphics Images – PictureBox control Drawing graphics - Graphics object Multimedia controls PictureBox control Image property – select image Choose how.

Slides:



Advertisements
Similar presentations
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
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.
 putpixel function plots a pixel at location (x, y) of specified color.  Declaration :- void putpixel(int x, int y, int color);
Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
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.
PHY-102 SAPIntroductory GraphicsSlide 1 Introductory Graphics In this section we will learn how about how to draw graphics on the screen in Java:  Drawing.
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.
User Interface Programming in C#: Graphics
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.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
Visual Basic Graphics Warning: The way I am using Visual Basic graphics is somewhat different (and much simpler!) to that of the book. Use these slides.
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.
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,
Graphics Standard Grade Computing. Graphics Package n A graphics package is another General Purpose Package. n It is used to draw pictures on the monitor.
CS324e - Elements of Graphics and Visualization Java2D Graphics.
Lecture Set 13 Drawing Mouse and Keyboard Events Part A - Drawing.
1 Windows Printing. 2 Objectives You will be able to Output text and graphics to a printer. Print multipage documents. Use the standard Windows print.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface A Brief Introduction to GDI+ S.R.G. Fraser, Pro Visual C++/CLI.
Visual C++ Programming: Concepts and Projects Chapter 6A: Methods (Concepts)
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.
C# Programming Lecture 4 “GDI+” PGL01/CSP/2006.
Graphics and Multimedia Part #2
Introduction to Flash. Topics What is Flash? What can you do with it? Simple animation Complex interactive web application, such as an online store. Starting.
Image Representation. Objectives  Bitmaps: resolution, colour depth and simple bitmap file calculations.  Vector graphics: drawing list – objects and.
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.
Drawing and Filling Geometric Shapes. Java comes with more than just points and lines. Within the Graphics2D class, there are also methods for drawing.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 2 Graphics Programming with C++ and the Dark GDK Library Starting.
Chapter 7 Graphics. © Daly and Wrigley Objectives Use Graphic Components: ▫ Strings ▫ Lines ▫ Rectangles ▫ Ovals ▫ Arcs Change the color and font of elements.
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.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
Exploring the Macromedia Flash Workspace – Lesson 2 1 Exploring the Macromedia Flash Workspace Lesson 2.
Introduction to Java Chapter 8 - Introduction to Java Graphics1 Chapter 8 Introduction to Java Graphics.
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.
CRE Programming Club - Class 5 Robert Eckstein and Robert Heard.
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.
Resources & Bitmaps Adding clip art to your application.
Please open JCreator and follow these steps: 1)Configure  Options 2)JDK Tools 3)Choose Run Applet from drop-down 4)Click Default, then Edit 5)Click the.
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.
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)
Adobe Photoshop CS5.
12 Graphics and Java 2D™.
Flash Interface, Commands and Functions
Graphics.
Basic Graphics Chapter 5 3/19/15 Thursday Section Only
Graphics and Multimedia
Computer Programming I
Graphics and Multimedia
Drawing Mouse and Keyboard Events Part A - Drawing
Basic Graphics Drawing Shapes 1.
ThS. Nguyễn Hà Giang Khoa CNTT - Hutech
CASE Tools Graphical User Interface Programming Using C#
© Hugh McCabe 2000 Web Authoring Lecture 7
Graphics and Multimedia
Chapter 12 Graphics in Windows and the Web
CPT 450 Computer Graphics 3rd Lecture.
Presentation transcript:

Graphics Images – PictureBox control Drawing graphics - Graphics object Multimedia controls PictureBox control Image property – select image Choose how to display – stretch,auto, centre, zoom

Graphics Object Graphics Objects are created by calling the CreateGraphics() method of the component on which the drawing is to performed. For example, a Graphics Object can be created on our Form called Form1 by calling CreateGraphics() method as follows in the Paint() method: private void Form1_Paint(object sender, PaintEventArgs e) { System.Drawing.Graphics graphicsObj; graphicsObj = this.CreateGraphics(); }

Graphics Drawing Graphics Graphics object is created on an object – e.g. a form or panel A pen or brush object is defined Pens for lines, brush for fill areas Graphics methods are called to draw or paint. Text, Lines and shapes can be drawn Origin (0,0) is top left-hand corner of screen

Creating a Pen A Graphics Object is of little use without a Pen object with which to draw (much as a sheet of paper is no good without a pen or pencil). A Pen object may be quite easily created as follows: Pen variable_name = new Pen (color, width); where variable_name is the name to be assigned to the Pen object, color is the color of the pen and width is the width of the lines to be drawn by the pen. For example, we can create red pen that is 5 pixels wide as follows: private void Form1_Paint(object sender, PaintEventArgs e) { System.Drawing.Graphics graphicsObj; graphicsObj = this.CreateGraphics(); Pen myPen = new Pen(System.Drawing.Color.Red, 5); }

Creating a Pen Once a Pen object has been created other properties may be changed. For example, the DashStyle property can be modified to change the style of line (i.e Dash, DashDot, DashDotDot, Dot, Solid or Custom). Properties such as the color and width may similarly be changed after a Pen has been created: for example: myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot; myPen.Color = System.Drawing.Color.RoyalBlue; myPen.Width = 3;

Drawing Lines Lines are drawn in C# using the DrawLine() method of the Graphics Object. This method takes a pre-instantiated Pen object and two sets of x and y co-ordinates (the start and end points of the line) as arguments. For example, to draw a line from co-ordinates (20, 20) to (200, 210) on our sample form: private void Form1_Paint(object sender, PaintEventArgs e) { System.Drawing.Graphics graphicsObj; graphicsObj = this.CreateGraphics(); Pen myPen = new Pen(System.Drawing.Color.Red, 5); graphicsObj.DrawLine(myPen, 20, 20, 200, 210); } The output will be like this:

Drawing Squares & Rectangles For the purposes of drawing rectangles and squares in C# the GraphicsObject provides the DrawRectangle() method. There are two ways to use the DrawRectangle() method. One is to pass through a Rectangle object and Pen and the other is to create an instance of a Rectangle object and pass that through along with the Pen. We will begin by looking at drawing a rectangle without a pre-created Rectangle object. The syntax for this is: graphicsobj.DrawRectangle(pen, x, y, width, height); The alternative is to pass through a Rectangle object in place of the co- ordinates and dimensions.The syntax for creating a Rectangle object is Rectangle rectangleObj = new Rectangle (x, y, width, height); Once a Rectangle object has been instantiated the syntax to call DrawRectangle() is as follows: graphicsobj.DrawRectangle(pen, x, y, rectangleobj);

Drawing Squares & Rectangles The following example creates a Rectangle which is then used as an argument to DrawRectangle(): private void Form1_Paint(object sender, PaintEventArgs e) { System.Drawing.Graphics graphicsObj; graphicsObj = this.CreateGraphics(); Pen myPen = new Pen(System.Drawing.Color.Red, 5); Rectangle myRectangle = new Rectangle(20, 20, 250, 200); graphicsObj.DrawRectangle(myPen, myRectangle); The out of the following code is :

Drawing Ellipses &Circles Ellipses and circles are drawn in C# using the DrawEllipse() method of the GraphicsObject class. The size of the shape to be drawn is defined by specifying a rectangle into which the shape must fit. As with the DrawRectangle() method, there are two ways to use the DrawEllipse() method. One is to pass through a Rectangle object and Pen and the other is to create an instance of a Rectangle object and pass that through along with the Pen. To draw an ellipse without first creating a Rectangle object use the following syntax: graphicsobj.DrawEllipse(pen, x, y, width, height); The alternative is to pass through a Rectangle object in place of the co- ordinates and dimensions. The syntax for creating a Rectangle object in C# is as follows: Rectangle rectangleObj = new Rectangle (x, y, width, height); Once a Rectangle object has been instantiated the syntax to call DrawRectangle() is as follows: graphicsobj.DrawEllipse(pen, x, y, rectangleobj);

Drawing Ellipses &Circles The following example creates a Rectangle which is then used as an argument to DrawEllipse(): private void Form1_Paint(object sender, PaintEventArgs e) { System.Drawing.Graphics graphicsObj; graphicsObj = this.CreateGraphics(); Pen myPen = new Pen(System.Drawing.Color.Green, 5); Rectangle myRectangle = new Rectangle(20, 20, 250, 200); graphicsObj.DrawEllipse(myPen, myRectangle); } The out of the following code is:

Drawing Text Text is drawn onto a Graphics Object using the DrawText() method. The syntax for this method is as follows: graphicsobj.DrawString(string, font, brush, x, y); The string argument specifies the text to be drawn. Font defines the font to be used to display the text and requires the creation of a Font object. The brush object is similar to the Pen object used to draw shapes with the exception that it specifies a fill pattern. Finally, the x and y values specify the top left hand corner of the text. In order to create a Font object a font size, font family and font style may be specified. For example to create a Helvetica, 40 point Italic font: Font myFont = new System.Drawing.Font("Helvetica", 40, FontStyle.Italic); A brush object is created by specifying by calling the appropriate constructor for the brush type and specifying a color: Brush myBrush = new SolidBrush(System.Drawing.Color.Red);

Drawing Text Having created the necessary objects we can incorporate these into our example C# application to draw some text: private void Form1_Paint(object sender, PaintEventArgs e) { System.Drawing.Graphics graphicsObj; graphicsObj = this.CreateGraphics(); Font myFont = new System.Drawing.Font("Helvetica", 40, FontStyle.Italic); Brush myBrush = new SolidBrush(System.Drawing.Color.Red); graphicsObj.DrawString("Hello C#", myFont, myBrush, 30, 30); The output of the following code is :