Graphics.

Slides:



Advertisements
Similar presentations
User Interface Programming in C#: Graphics
Advertisements

You can insert graphics onto your page by clicking on the Picture Frame Tool icon and then drawing a frame for your graphic. Double click in the frame.
2 Part II Enhancing a Presentation Changing the Presentation Design Design template Professionally created slide designs contain –Color schemes –Custom.
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
Text, Masks, and Live Effects – Lesson 41 Text, Masks, and Live Effects Lesson 4.
Working with Microsoft PowerPoint /6/
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,
Reporting Aesthetics An ACEware Webinar 1:00-2:00 pm February 14 th, 2008.
By: Zaiba Mustafa Copyright ©
Lecture Set 13 Drawing Mouse and Keyboard Events Part A - Drawing.
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.
Tutorial 6 Working with Bitmaps and Gradients, and Publishing Flash Files.
Tutorial 2 Drawing Text, Adding Shapes, and Creating Symbols.
Object Oriented Programming Graphics and Multimedia Dr. Mike Spann
C# Programming Lecture 4 “GDI+” PGL01/CSP/2006.
Graphics and Multimedia Part #2
BIM211 – Visual Programming Objects, Collections, and Events 1.
Adobe Fireworks CS3 Revealed CHAPTER ONE: GETTING STARTED WITH ADOBE FIREWORKS.
GDI+ 1. Objectives 2 GDI+ class  Create and render Graphic  Display information on the computer screen, printer 3.
Creating Web Pages Chapter 5 Learn how to… Identify Web page creation strategies. Define HTML Web page elements. Describe the principles of good screen.
IT: Web Technologies: Web Animation 1 Copyright © Texas Education Agency, All rights reserved. 1 Web Technologies Designing Web Site Layout Using.
Lecture 5 Graphics Erick Pranata. » Graphics Overview » About GDI+ » Getting Started.
Računarska grafika GDI+ (Graphics Device Interface Plus)
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.
© 2004 by the McGraw-Hill Companies, Inc. All rights reserved. Lecture 29 Enhancing Presentations with Graphics (2)
Advanced 2D Design Concepts Guilford County Sci Vis V
Windows XP Lab 3 Using Applications Competencies.
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.
Resources & Bitmaps Adding clip art to your application.
Advanced 2D Design Concepts V The basic fill options include uniform or solid, fountain or gradient, and pattern. The uniform fill is produced.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
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.
Chapter 4 Drawing and Painting with Color
(PART II) Graphics and Multimedia 11/02/1437 Lect6 (Part 2)
Chapter 11 Enhancing an Online Form and Using Macros Microsoft Word 2013.
2.02F Adding and Animating Text in Computer Animations
Chapter 3: I Need a Tour Guide (Introduction to Visual Basic 2012)
Adobe Photoshop CS5.
THE INDUSTRIAL REVOLUTION Capitalism v. Socialism
OVERVIEW Objectives Follow a design document to prepare images for inclusion in a Web page Run a batch process to prepare multiple images in one step Use.
Microsoft Office Illustrated
5/23/2018 Additional Features of WordPad
Bitmap Basics in Fireworks
Chapter 2 – Introduction to the Visual Studio .NET IDE
Graphics and Multimedia
Microsoft PowerPoint 2003 Illustrated Introductory
Drawing Mouse and Keyboard Events Part A - Drawing
2.02E Adding and Animating Text into Computer Animations
ThS. Nguyễn Hà Giang Khoa CNTT - Hutech
CASE Tools Graphical User Interface Programming Using C#
Chapter Lessons Understand the Fireworks work environment
© Hugh McCabe 2000 Web Authoring Lecture 7
POWER POINT WHY HAVE WE USE THIS PROGRAM? TO SHOW YOUR STUDY..
Photoshop Bell Work Hand Tool: The hand tool moves an image within its window Zoom Tool: The Zoom Tool magnifies and reduces the view of an image. CTRL.
Repetition and Multiple Forms
2.02E Adding and Animating Text into Computer Animations
Construction Paper Mosaic Art
Graphics and Multimedia
Microsoft Publisher 2016.
Changing and Customizing Maps
TEXT FORMAT Textured and layered background with title - Advanced
Foundation Level Course
TIMELINE DISPLAY– Style 6
Presentation transcript:

Graphics

Parts: 1) Drawing Graphics 2) Working with Images 3) Formatting Text

Drawing Graphics

System.Drawing Namespace

How to Specify the Location and Size of Controls button1.Location = new Point(10, 10); button1.Left = 10; button1.Top = 10; button1.Size = new Size(30, 30);

How to Specify the Color of Controls button1.ForeColor = Color.Red; button1.BackColor = Color.Blue; button1.ForeColor = Color.FromArgb(10, 200, 200); button1.BackColor = Color.FromArgb(200, 5, 5);

How to Draw Lines and Shapes Create a Graphics object by calling the System.Windows.Forms.Control.CreateGrahics method. 2. Create a Pen object. 3. Call a member of the Graphics class to draw on the control using the Pen.

Graphics Class Members

private void Form1_Paint(object sender, PaintEventArgs e) { // Create a graphics object from the form Graphics g = this.CreateGraphics(); // Create a pen object with which to draw Pen p = new Pen(Color.Red, 7); Draw the line g.DrawLine(p, 1, 1, 100, 100); }

Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.Blue, 3); g.DrawPie(p, 1, 1, 100, 100, -30, 60);

Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.MediumPurple, 2); //Create an array of points Point[] points = new Point[] {new Point(10, 10), new Point(10, 100), new Point(50, 65), new Point(100, 100), new Point(85, 40)}; //Draw a shape defined by the array of points g.DrawPolygon(p, points);

Graphics g = this. CreateGraphics(); Pen p = new Pen(Color. Red, 7); p Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.Red, 7); p.DashStyle = DashStyle.Dot; g.DrawLine(p, 50, 25, 400, 25); p.DashStyle = DashStyle.Dash; g.DrawLine(p, 50, 50, 400, 50); p.DashStyle = DashStyle.DashDot; g.DrawLine(p, 50, 75, 400, 75); p.DashStyle = DashStyle.DashDotDot; g.DrawLine(p, 50, 100, 400, 100); p.DashStyle = DashStyle.Solid; g.DrawLine(p, 50, 125, 400, 125);

Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.Red, 10); p.StartCap = LineCap.ArrowAnchor; p.EndCap = LineCap.DiamondAnchor; g.DrawLine(p, 50, 25, 400, 25); p.StartCap = LineCap.SquareAnchor; g.DrawLine(p, 50, 50, 400, 50); p.StartCap = LineCap.Flat; p.EndCap = LineCap.Round; g.DrawLine(p, 50, 75, 400, 75); p.StartCap = LineCap.RoundAnchor; p.EndCap = LineCap.Square; g.DrawLine(p, 50, 100, 400, 100);

How to Fill Shapes ■ System.Drawing.Drawing2D.HatchBrush Defines a rectangular brush with a hatch style, a foreground color, and a background color ■System.Drawing.Drawing2D.LinearGradientBrush Encapsulates a brush with a linear gradient that provides a visually appealing, professional-looking fill. ■ System.Drawing.Drawing2D.PathGradientBrush Provides similar functionality to LinearGradientBrush; however, you can define a complex fill pattern that fades between multiple points. ■ System.Drawing.SolidBrush Defines a brush of a single color ■ System.Drawing.TextureBrush Defines a brush made from an image that can be tiled across a shape, like a wallpaper design.

Graphics g = this.CreateGraphics(); Brush b = new SolidBrush(Color.Maroon); Point[] points = new Point[] {new Point(10, 10), new Point(10, 100), new Point(50, 65), new Point(100, 100), new Point(85, 40)}; g.FillPolygon(b, points);

Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.Maroon, 2); Brush b = new LinearGradientBrush(new Point(1,1), new Point(100,100), Color.White, Color.Red); Point[] points = new Point[] {new Point(10, 10), new Point(10, 100), new Point(50, 65), new Point(100, 100), new Point(85, 40)}; g.FillPolygon(b, points); g.DrawPolygon(p, points);

Summary ■ The System.Drawing namespace provides tools for drawing graphics and editing existing images. The most useful classes are Graphics, Image, and Bitmap. ■ Use the Point and Size classes to specify the location and size of controls. ■ The System.Drawing.Color structure provides predefined properties for common colors. ■ To draw lines and shapes, create an instance of the Graphics class, create a Pen object, and then call one of the Graphics member methods to draw a line or a shape using the Pen instance.

Working with Images

The Image and Bitmap Classes

How to Display Pictures Image i = Image.FromFile(@"C:\windows\gone fishing.bmp"); pictureBox1.BackgroundImage = i; Bitmap b = new Bitmap(@"C:\windows\gone fishing.bmp"); pictureBox1.BackgroundImage = b; Bitmap bm = new Bitmap(@"C:\WINDOWS\Web\Wallpaper\Azul.jpg"); Graphics g = this.CreateGraphics(); g.DrawImage(bm, 1, 1, this.Width, this.Height);

How to Create and Save Pictures Bitmap bm = new Bitmap(600, 600); Graphics g = Graphics.FromImage(bm); Brush b = new LinearGradientBrush(new Point(1, 1), new Point(600, 600), Color.White, Color.Red); Point[] points = new Point[] {new Point(10, 10), new Point(77, 500), new Point(590, 100), new Point(250, 590), new Point(300, 410)}; g.FillPolygon(b, points); bm.Save("bm.jpg", ImageFormat.Jpeg);

How to Use Icons Graphics g = this.CreateGraphics(); g.DrawIcon(SystemIcons.Question, 40, 40);

Summary ■ The Image and Bitmap classes enable you to edit or create pictures, and save the results as a file. ■ To display a picture in a Windows Forms assembly, load the picture into an instance of the Image or Bitmap class, create an instance of the PictureBox control, and then use the Image or Bitmap object to define the PictureBox.BackgroundImage property. ■ To create and save a picture, create a Bitmap object, edit it using a Graphics object, and then call the Bitmap.Save method. ■ To display an icon, call the Graphics.DrawIcon or Graphics.DrawIconUnstretched methods using one of the properties of the SystemIcons class.

Formatting Text

How to Add Text to Graphics 1. Create a Graphics object. 2. Create a Font object. 3. Optionally, create a Brush object. 4. Call Graphics.DrawString and specify the location for the text.

How to Create a Font Object Font f = new Font("Arial", 12, FontStyle.Bold); FontFamily ff = new FontFamily("Arial"); Font f = new Font(ff, 12); FontConverter converter = new FontConverter(); Font f = (Font)converter.ConvertFromString("Arial, 12pt");

How to Write Text Graphics g = this.CreateGraphics(); Font f = new Font("Arial", 40, FontStyle.Bold); g.DrawString("Hello, World!", f, Brushes.Blue, 10, 10);

How to Control the Formatting of Text StringFormat class

Graphics g = this.CreateGraphics(); // Construct a new Rectangle. Rectangle r = new Rectangle(new Point(40, 40), new Size(80, 80)); // Construct 2 new StringFormat objects StringFormat f1 = new StringFormat(StringFormatFlags.NoClip); StringFormat f2 = new StringFormat(f1); // Set the LineAlignment and Alignment properties for // both StringFormat objects to different values. f1.LineAlignment = StringAlignment.Near; f1.Alignment = StringAlignment.Center; f2.LineAlignment = StringAlignment.Center; f2.Alignment = StringAlignment.Far; f2.FormatFlags = StringFormatFlags.DirectionVertical; // Draw the bounding rectangle and a string for each // StringFormat object. g.DrawRectangle(Pens.Black, r); g.DrawString("Format1", this.Font, Brushes.Red, (RectangleF)r, f1); g.DrawString("Format2", this.Font, Brushes.Red, (RectangleF)r, f2);

Summary ■ To add text to graphics, create a Graphics object, create a Font object, optionally create a Brush object, and then call the Graphics.DrawString method. ■ To create a Font object, pass the font family name, font size, and font style. ■ Write text by calling the Graphics.DrawString method. The DrawString method requires a Font object, a Brush object that specifies the color of the text, and the location to draw the text. ■ Use the StringFormat class to control the formatting of text. You can use this class to change the direction of the text, or to change the alignment of text.

Your Key Competences ■ Describe the members of the System.Drawing namespace. ■ Control the location, size, and color of controls. ■ Draw lines, empty shapes, and solid shapes. ■ Customize pens and brushes to enhance graphics. ■ Describe the purpose of the Image and Bitmap classes. ■ Display pictures in forms or PictureBox objects. ■ Create a new picture, add lines and shapes to the picture, and save it as a file. ■ Describe the process of creating the objects required to add text to images. ■ Create Font objects to meet your requirements for type, size, and style. ■ Use Graphics.DrawString to annotate images with text. ■ Control the formatting of text.

Key Terms ■ Bitmap ■ Brush ■ Graphics ■ Pen