Računarska grafika GDI+ (Graphics Device Interface Plus)

Slides:



Advertisements
Similar presentations
Chapter 9 Color, Sound and Graphics
Advertisements

COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
Chapter 3 Drawing and Composing an Illustration. Objectives Draw straight lines Draw curved lines Draw elements of an illustration Apply attributes to.
Graphics and Multimedia Session 13 Mata kuliah: M0874 – Programming II Tahun: 2010.
User Interface Programming in C#: Graphics
Chapter 7 Creating Graphics. Chapter Objectives Use the Pen tool Reshape frames and apply stroke effects Work with polygons and compound paths Work with.
1 L38 Graphics and Java 2D™ (3). 2 OBJECTIVES In this chapter you will learn:  To understand graphics contexts and graphics objects.  To understand.
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
Macromedia Fireworks MX 2004 – Design Professional WORKING WITH OBJECTS.
SWE 423: Multimedia Systems Chapter 4: Graphics and Images.
Syracuse University 3D Framework using GDI+.Net Carmen Vaca Ruiz Independent Study Fall 2004 Instructor: Dr. Jim Fawcett.
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,
Lecture Set 13 Drawing Mouse and Keyboard Events Part A - Drawing.
Working with Graphics. Objectives Understand bitmap and vector graphics Place a graphic into a frame Work with the content indicator Transform frame contents.
Vector Graphics Making custom images. Raster vs. Vector Graphics In computer graphics, a raster graphics image, or bitmap, is a dot matrix data structure.
Adobe Flash CS4 – Illustrated Unit B: Creating Graphics and Text.
Macromedia Fireworks 8 Revealed WORKING WITH OBJECTS.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface A Brief Introduction to GDI+ S.R.G. Fraser, Pro Visual C++/CLI.
© 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.
Object Oriented Programming Graphics and Multimedia Dr. Mike Spann
C# Programming Lecture 4 “GDI+” PGL01/CSP/2006.
Graphics and Multimedia Part #2
Adobe Illustrator Basics Instructor: Cristol Gregory Assistant: Tara Caimi.
Digital Media Dr. Jim Rowan ITEC Vector Graphics Elegant way to construct digital images that –have a compact representation –are scalable –are.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Advanced User Interfaces with Java SD’98 - Session 3206 Ted Faison Faison Computing Inc.
GDI+ 1. Objectives 2 GDI+ class  Create and render Graphic  Display information on the computer screen, printer 3.
INT 840E Computer graphics Introduction & Graphic’s Architecture.
Lecture 5 Graphics Erick Pranata. » Graphics Overview » About GDI+ » Getting Started.
Illustrator I I450 Technology Seminar. Bitmap vs. Vector Photoshop = Bitmap Illustrator = Vector Bitmap images are resolution dependent Vector images.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
© 2010 Delmar, Cengage Learning Chapter 7 Creating Graphics.
Digital Media Dr. Jim Rowan ITEC So far… We have compared bitmapped graphics and vector graphics We have discussed bitmapped images, some file formats.
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.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
ADOBE INDESIGN CS3 Chapter 7 CREATING GRAPHICS. Chapter 72 Introduction InDesign allows you to create graphics using tools in InDesign The Pen Tool can.
Digital Media Dr. Jim Rowan ITEC Vector Graphics Elegant way to construct digital images that –have a compact representation –are scalable –are.
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.
Digital Media Lecture 5: Vector Graphics Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
GDI +. Graphics class's methods System.Drawing Graphics Objects.
Mohammed AM Dwikat CIS Department Digital Image.
IS502:M ULTIMEDIA D ESIGN FOR I NFORMATION S YSTEM D IGITAL S TILL I MAGES Presenter Name: Mahmood A.Moneim Supervised By: Prof. Hesham A.Hefny Winter.
Main characteristics of Vector graphics  Vector graphics provide an elegant way of constructing digital images (diagrams, technical illustration and.
AN ILLUSTRATION DRAWING AND COMPOSING Adobe Illustrator CS Design Professional.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
CSI-447: Multimedia Systems
Adobe Flash Professional CS5 – Illustrated
Lines, Curves, and Area Fill
Graphics.
Dr. Jim Rowan ITEC 2110 Wednesday, September 12
Graphics and Multimedia
IMAGES.
Computer Programming I
Graphics and Multimedia
"Digital Media Primer" Yue-Ling Wong, Copyright (c)2013 by Pearson Education, Inc. All rights reserved.
Drawing Mouse and Keyboard Events Part A - Drawing
Java Graphics The basic rendering mechanism is the drawing system that controls when and how programs can draw on a graphics component. When a component.
ThS. Nguyễn Hà Giang Khoa CNTT - Hutech
CASE Tools Graphical User Interface Programming Using C#
Chapter Lessons Understand the Fireworks work environment
Digital Media Dr. Jim Rowan ITEC 2110.
CPT 450 Computer Graphics 3rd Lecture.
Lines, Curves and Area Fills
Presentation transcript:

Računarska grafika GDI+ (Graphics Device Interface Plus)

Introduction Windows GDI+ is the portion of the Windows XP operating system or Windows Server 2003 operating system that provides two-dimensional vector graphics, imaging, and typography. GDI+ improves on Windows Graphics Device Interface (GDI) (the graphics device interface included with earlier versions of Windows) by adding new features and by optimizing existing features.

The namespaces in GDI+ System.Drawing ▫This is the core GDI+ namespace. It defines objects for basic rendering (fonts, pens, basic brushes, etc.) and the most important object: Graphics. System.Drawing.Drawing2D ▫This gives you objects for more advanced two- dimensional vector graphics. Some of them are gradient brushes, pen caps, and geometric transforms.

The namespaces in GDI+ System.Drawing.Imaging ▫If you want to change graphical images - that is, change the palette, extract image metadata, manipulate metafiles, and so forth - this is the one you need. System.Drawing.Printing ▫To render images to the printed page, interact with the printer itself, and format the overall appearance of a print job, use the objects here.

The namespaces in GDI+ System.Drawing.Text ▫You can use collections of fonts with this namespace.

Graphics object The place to start with GDI+ is the Graphics object. Although the things you draw show up on your monitor or a printer, the Graphics object is the "canvas" that you draw on. Graphics object is always associated with a particular device context.

How do I get a Graphics object? You can get Graphics object from other objects. (e.g. event e parameter that is passed to the OnPaint event) You can use the CreateGraphicsmethod for a device context to create a Graphics object.

Example private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; g.DrawLine(new Pen(Color.Red), 0, 0, 250, 250); } -or- protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; g.DrawLine(new Pen(Color.Red), 0, 0, 250, 250); } -or- private void button1_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); g.DrawLine(new Pen(Color.Red), 0, 0, 250, 250); }

Vector Graphics versus Bitmaps "vector" is another word for a line, this way of using GDI+ is often called vector graphics. The other major type of graphics is create graphics using individual points of color like your TV or computer monitor does it. This is called bitmap graphics and will be covered in a later segment.

Coordinate spaces There are three distinct coordinate spaces in GDI+. These are: World coordinate space. This is where you put the coordinates that define lines, shapes and points in the 2 dimensional space of the graphics system. World coordinates are abstract values expressed as floating point numbers. Essentially, whenever you draw something it goes into this coordinate space. Page Coordinate Space. The Page space is where the world coordinates are transformed into some real-world value. You can make the Page Space represent pixels, inches millimeters and so-on. This is what makes GDI+ a resolution independent system. You control how the page space interprets the world space by telling the Graphics object what PageUnit is being used and adjusting the PageScale. Device Coordinate Space. This space is controlled by the system and enables the real-world values in the Page Space to be translated to your screen or printer. Device space ensures that a 1 inch long line looks an inch long on the screen and on the printer even though the two devices may have very different pixel resolutions. You have no direct control over this space.

Defining coordinate begining & orentations Graphics g = e.Graphics; GraphicsState StanjePre = g.Save(); g.PageUnit = GraphicsUnit.Pixel; Matrix matricaTransformacija = new Matrix(1, 0, 0, -1, 0, 0); matricaTransformacija.Translate(this.ClientRectangl e.Width / 2, -this.ClientRectangle.Height / 2); g.Transform = matricaTransformacija; g.DrawLine(new Pen(Color.FromArgb(255, 0, 0), 3), 0, 0, 100, 100); g.Restore(StanjePre); g.DrawLine(new Pen(Color.FromArgb(0, 255, 0), 3), 0, 0, 100, 100);

Color Color.FromArgb(255, 0, 0); Color.FromArgb(128, 255, 0, 0); Color.FromName("red"); Color.FromKnownColor(KnownColor.Red); Color.Red;

Pen NameDescription Pen(Brush) Initializes a new instance of the Pen class with the specified Brush.Brush Pen(Color) Initializes a new instance of thePen class with the specified color. Pen(Brush, Single) Initializes a new instance of the Pen class with the specified Brush and Width.BrushWidth Pen(Color, Single)Initializes a new instance of the Pen class with the specified Color and Width properties.ColorWidth

Pen // Create a new pen. Pen skyBluePen = new Pen(Brushes.DeepSkyBlue); // Set the pen's width. skyBluePen.Width = 8.0F; // Set the LineJoin property. skyBluePen.LineJoin = LineJoin.Bevel; // Draw a rectangle. e.Graphics.DrawRectangle(skyBluePen, new Rectangle(40, 40, 150, 200)); //Dispose of the pen. skyBluePen.Dispose();

LineCap – Start & End MemberDescription FlatSpecifies a flat line cap. SquareSpecifies a square line cap. RoundSpecifies a round line cap. TriangleSpecifies a triangular line cap. NoAnchorSpecifies no anchor. SquareAnchorSpecifies a square anchor line cap. RoundAnchorSpecifies a round anchor cap. DiamondAnchorSpecifies a diamond anchor cap. ArrowAnchorSpecifies an arrow-shaped anchor cap. CustomSpecifies a custom line cap. AnchorMaskSpecifies a mask used to check whether a line cap is an anchor cap. Olovka.StartCap = LineCap.DiamondAnchor; Olovka.EndCap = LineCap.Triangle; g.DrawLine(Olovka, 50, 500, 500, 500); Olovka.StartCap = LineCap.DiamondAnchor; Olovka.EndCap = LineCap.Triangle; g.DrawLine(Olovka, 50, 500, 500, 500);

LineJoin MemberDescription Miter Specifies a mitered join. This produces a sharp corner or a clipped corner, depending on whether the length of the miter exceeds the miter limit. Bevel Specifies a beveled join. This produces a diagonal corner. Round Specifies a circular join. This produces a smooth, circular arc between the lines. MiterClippedSpecifies a mitered join. This produces a sharp corner or a beveled corner, depending on whether the length of the miter exceeds the miter limit. Olovka.LineJoin = LineJoin.Bevel;

DashStyle MemberDescription SolidSpecifies a solid line. Dash Specifies a line consisting of dashes. Dot Specifies a line consisting of dots. DashDot Specifies a line consisting of a repeating pattern of dash-dot. DashDotDot Specifies a line consisting of a repeating pattern of dash-dot-dot. Custom Specifies a user-defined custom dash style. Pen Olovka = new Pen(Color.Black, 10); float[] NasaIsprekLinija = {5.0f, 2.0f, 1.0f, 3.0f}; Olovka.DashPattern = NasaIsprekLinija; Pen Olovka = new Pen(Color.Black, 10); float[] NasaIsprekLinija = {5.0f, 2.0f, 1.0f, 3.0f}; Olovka.DashPattern = NasaIsprekLinija; Olovka.DashStyle = DashStyle.DashDot;

Drawing basic shapes To draw lines with Windows GDI+ you need to create a Graphics object and a Pen object.GraphicsPen The Graphics object provides the methods that actually do the drawing, and the Pen object stores attributes of the line, such as color, width, and style.

Basic shapes Lines Rectangles Ellipses Arcs Pies Polygons Cardinal Splines Bézier Splines Paths Open and Closed Curves Regions Clipping

Lines public void DrawLine(Pen pen, Point pt1, Point pt2 ); Pen Type: System.Drawing.Pen Pen that determines the color, width, and style of the line.System.Drawing.Pen Pen Pt1 Type: System.Drawing.Point Point structure that represents the first point to connect. System.Drawing.Point Point Pt2 Type: System.Drawing.Point Point structure that represents the second point to connect. System.Drawing.Point Point

Lines g.DrawLine(new Pen(Color.Red, 3.2f), 0, 0, 250, 250); Point PocetnaTacka = new Point(0,0); Point KrajnjaTacka = new Point(250,50); Pen Olovka = new Pen(Color.GreenYellow, 3.2f); g.DrawLine(Olovka, PocetnaTacka, KrajnjaTacka);

Rectangles public void DrawRectangle( Pen pen, Rectangle rect ) Pen Type: System.Drawing.Pen A Pen that determines the color, width, and style of the rectangle. System.Drawing.PenPen Rect Type: System.Drawing.Rectangle A Rectangle structure that represents the rectangle to draw. System.Drawing.RectangleRectangle

Rectangles g.DrawRectangle(new Pen(Color.Blue, 2.5f), 50, 50, 150, 100); g.DrawRectangle(new Pen(Color.Blue, 2.5f), new Rectangle(50, 50, 100, 50));

Elipses public void DrawEllipse( Pen pen, Rectangle rect ) Pen Type: System.Drawing.Pen A Pen that determines the color, width, and style of the rectangle. System.Drawing.PenPen Rect Type: System.Drawing.Rectangle A Rectangle structure that represents the rectangle to draw. System.Drawing.RectangleRectangle

Ellipses g.DrawEllipse(new Pen(Color.Black, 3), 50, 50, 150, 100); g.DrawEllipse(new Pen(Color.Blue, 2.5f), new Rectangle(50, 50, 100, 50));

Arcs g.DrawArc(new Pen(Color.Black, 3), 50, 50, 150, 100, 0, 140);

Pies Graphics g = e.Graphics; Matrix matricaTransformacija = new Matrix(1, 0, 0, -1, 0, 0); matricaTransformacija.Translate(this.ClientRectangle.Width / 2, -this.ClientRectangle.Height / 2); g.Transform = matricaTransformacija; g.DrawLine(new Pen(Color.Black), -this.ClientRectangle.Width / 2, 0, this.ClientRectangle.Width / 2, 0); g.DrawLine(new Pen(Color.Black), 0, this.ClientRectangle.Height / 2, 0, - this.ClientRectangle.Height / 2); Pen Olovka = new Pen(Color.FromName("red"), 3); g.DrawPie(Olovka, -100, -100, 200, 200, 0, 300);

Pies

Polygons Point [] tacke = new Point[] { new Point(100, 25), new Point(25, 100), new Point(150, 200), new Point(275, 100), new Point(200, 25)}; Pen Olovka = new Pen(Color.Black, 3); g.DrawPolygon(Olovka, tacke);

Cardinal & Bézier Splines

Bézier Splines

Paths Paths are formed by combining lines, rectangles, and simple curves. ▫Lines ▫Rectangles ▫Ellipses ▫Arcs ▫Polygons ▫Cardinal splines ▫Bézier splines

Paths GraphicsPath gp = new GraphicsPath(FillMode.Alternate); //gp.AddPolygon(tacke); gp.AddLine(50, 150, 50, 350); gp.AddLine(50, 350, 250, 350); gp.AddArc(250, 250, 400, 200, 180, -180); gp.AddLine(650, 350, 850, 350); gp.AddLine(850, 350, 850, 150); gp.AddLine(850, 150, 650, 150); gp.Ad,dArc(250, 50, 400, 200, 0, -180); //gp.CloseFigure(); gp.AddLine(250, 150, 50, 150); gp.AddRectangle(new Rectangle(300, 200, 300, 100));

Paths g.FillPath(new SolidBrush(Color.Yellow), gp); g.DrawPath(Olovka, gp);

Brushes: To fill a closed shape, you need a Graphics object and a Brushobject.GraphicsBrush ▫Solid Brushes ▫Hatch Brushes ▫Texture Brushes ▫Gradient Brushes

Solid Brushes public SolidBrush( Color color ) color Type: System.Drawing.Color A Color structure that represents the color of this brush. System.Drawing.ColorColor

Solid Brushes g.Clear(Color.Black); SolidBrush CetkaR = new SolidBrush(Color.FromArgb(128, 255, 0, 0)); SolidBrush CetkaG = new SolidBrush(Color.FromArgb(128, 0, 255, 0)); SolidBrush CetkaB = new SolidBrush(Color.FromArgb(128, 0, 0, 255)); g.FillEllipse(CetkaR, 50, 50, 300, 300); g.FillEllipse(CetkaG, 250, 50, 300, 300); g.FillEllipse(CetkaB, 150, 200, 300, 300);

Hatch Brushes public HatchBrush( HatchStyle hatchstyle, Color foreColor, Color backColor ) hatchstyle Type: System.Drawing.Drawing2D.HatchStyle One of the HatchStyle values that represents the pattern drawn by this HatchBrush. System.Drawing.Drawing2D.HatchStyleHatchStyleHatchBrush foreColor Type: System.Drawing.Color The Color structure that represents the color of lines drawn by this HatchBrush. System.Drawing.ColorColorHatchBrush backColor Type: System.Drawing.Color The Color structure that represents the color of spaces between the lines drawn by this HatchBrush. System.Drawing.ColorColorHatchBrush

Hatch Brushes g.Clear(Color.White); HatchBrush Cetka = new HatchBrush(HatchStyle.Cross, Color.Green); HatchBrush Cetka1 = new HatchBrush(HatchStyle.Cross, Color.Black, Color.Red); HatchBrush Cetka2 = new HatchBrush(HatchStyle.Divot, Color.Yellow, Color.Blue); g.FillEllipse(Cetka, 50, 50, 300, 300); g.FillEllipse(Cetka1, 250, 50, 300, 300); g.FillEllipse(Cetka2, 150, 200, 300, 300);

Texture Brushes g.Clear(Color.White); Image slika = Image.FromFile("C:\\Documents and Settings\\Ognjen\\Desktop\\RG\\slike\\texture__.jpg"); Image slika1 = Image.FromFile("C:\\Documents and Settings\\Ognjen\\Desktop\\RG\\slike\\Y-YellowTexture.bmp"); Image slika2 = Image.FromFile("newwall.bmp"); TextureBrush Cetka = new TextureBrush(slika); TextureBrush Cetka1 = new TextureBrush(slika1); TextureBrush Cetka2 = new TextureBrush(slika2);