računarska grafika
DESCRIPTION
Računarska grafika. GDI+ ( Graphics Device Interface Plus). Introduction. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/1.jpg)
Računarska grafikaGDI+(Graphics Device Interface Plus)
![Page 2: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/2.jpg)
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.
![Page 3: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/3.jpg)
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.
![Page 4: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/4.jpg)
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.
![Page 5: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/5.jpg)
The namespaces in GDI+•System.Drawing.Text
▫You can use collections of fonts with this namespace.
![Page 6: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/6.jpg)
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.
![Page 7: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/7.jpg)
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.
![Page 8: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/8.jpg)
Exampleprivate 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);
}
![Page 9: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/9.jpg)
![Page 10: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/10.jpg)
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.
![Page 11: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/11.jpg)
![Page 12: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/12.jpg)
Coordinate spacesThere 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.
![Page 13: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/13.jpg)
Defining coordinate begining & orentationsGraphics g = e.Graphics;GraphicsState StanjePre = g.Save();g.PageUnit = GraphicsUnit.Pixel;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.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);
![Page 14: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/14.jpg)
ColorColor.FromArgb(255, 0, 0);Color.FromArgb(128, 255, 0, 0);Color.FromName("red");Color.FromKnownColor(KnownColor.Red);Color.Red;
![Page 15: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/15.jpg)
PenName DescriptionPen(Brush) Initializes a new instance of the Pen class with the
specified 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.
Pen(Color, Single) Initializes a new instance of the Pen class with the specified Color and Width properties.
![Page 16: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/16.jpg)
Pen// Create a new pen. Pen skyBluePen = newPen(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();
![Page 17: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/17.jpg)
LineCap – Start & End Member DescriptionFlat Specifies a flat line cap.
Square Specifies a square line cap.
Round Specifies a round line cap.
Triangle Specifies a triangular line cap.
NoAnchor Specifies no anchor.
SquareAnchor Specifies a square anchor line cap.
RoundAnchor Specifies a round anchor cap.
DiamondAnchor Specifies a diamond anchor cap.
ArrowAnchor Specifies an arrow-shaped anchor cap.
Custom Specifies a custom line cap.
AnchorMask Specifies 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);
![Page 18: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/18.jpg)
LineJoin Member DescriptionMiter 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.
MiterClipped Specifies 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;
![Page 19: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/19.jpg)
DashStyle Member DescriptionSolid Specifies 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.
DashDotDotSpecifies 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;
Olovka.DashStyle = DashStyle.DashDot;
![Page 20: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/20.jpg)
Drawing basic shapesTo draw lines with Windows GDI+ you need
tocreate a Graphics object and a Pen object. 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.
![Page 21: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/21.jpg)
Basic shapes• Lines• Rectangles• Ellipses • Arcs• Pies• Polygons• Cardinal Splines• Bézier Splines• Paths• Open and Closed Curves• Regions• Clipping
![Page 22: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/22.jpg)
Lines
public void DrawLine(Pen pen, Point pt1, Point pt2 );
PenType: System.Drawing.PenPen that determines the color, width, and style of the
line.Pt1
Type: System.Drawing.PointPoint structure that represents the first point to
connect. Pt2
Type: System.Drawing.PointPoint structure that represents the second point to
connect.
![Page 23: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/23.jpg)
Linesg.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);
![Page 24: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/24.jpg)
Rectangles
public void DrawRectangle( Pen pen, Rectangle rect )
PenType: System.Drawing.PenA Pen that determines the color, width, and style of the rectangle.
RectType: System.Drawing.RectangleA Rectangle structure that represents the rectangle to draw.
![Page 25: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/25.jpg)
Rectanglesg.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));
![Page 26: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/26.jpg)
Elipses
public void DrawEllipse( Pen pen, Rectangle rect )
PenType: System.Drawing.PenA Pen that determines the color, width, and style of the rectangle.
RectType: System.Drawing.RectangleA Rectangle structure that represents the rectangle to draw.
![Page 27: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/27.jpg)
Ellipsesg.DrawEllipse(new Pen(Color.Black, 3), 50, 50, 150, 100);
g.DrawEllipse(new Pen(Color.Blue, 2.5f), new Rectangle(50, 50, 100, 50));
![Page 28: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/28.jpg)
Arcsg.DrawArc(new Pen(Color.Black, 3), 50, 50, 150, 100, 0, 140);
![Page 29: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/29.jpg)
PiesGraphics 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);
![Page 30: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/30.jpg)
Pies
![Page 31: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/31.jpg)
PolygonsPoint [] 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);
![Page 32: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/32.jpg)
Cardinal & Bézier Splines
![Page 33: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/33.jpg)
Bézier Splines
![Page 34: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/34.jpg)
Paths•Paths are formed by combining lines,
rectangles, and simple curves.▫Lines▫Rectangles▫Ellipses▫Arcs▫Polygons▫Cardinal splines▫Bézier splines
![Page 35: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/35.jpg)
PathsGraphicsPath 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));
![Page 36: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/36.jpg)
Pathsg.FillPath(new SolidBrush(Color.Yellow), gp);g.DrawPath(Olovka, gp);
![Page 37: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/37.jpg)
Brushes:•To fill a closed shape, you need a
Graphics object and a Brushobject.▫Solid Brushes▫Hatch Brushes▫Texture Brushes▫Gradient Brushes
![Page 38: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/38.jpg)
Solid Brushespublic SolidBrush( Color color )
colorType: System.Drawing.ColorA Color structure that represents the color of this brush.
![Page 39: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/39.jpg)
Solid Brushesg.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);
![Page 40: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/40.jpg)
Hatch Brushespublic HatchBrush( HatchStyle hatchstyle, Color foreColor,
Color backColor )
hatchstyleType: System.Drawing.Drawing2D.HatchStyleOne of the HatchStyle values that represents the pattern drawn by this HatchBrush.
foreColorType: System.Drawing.ColorThe Color structure that represents the color of lines drawn by this HatchBrush.
backColorType: System.Drawing.ColorThe Color structure that represents the color of spaces between the lines drawn by this HatchBrush.
![Page 41: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/41.jpg)
![Page 42: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/42.jpg)
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);
![Page 43: Računarska grafika](https://reader035.vdocuments.us/reader035/viewer/2022062223/56812c2a550346895d90a1b3/html5/thumbnails/43.jpg)
Texture Brushesg.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);