Az előadás letöltése folymat van. Kérjük, várjon

Az előadás letöltése folymat van. Kérjük, várjon

Vizuális programozás Rajzolás Windows Forms alkalmazásokban GDI+

Hasonló előadás


Az előadások a következő témára: "Vizuális programozás Rajzolás Windows Forms alkalmazásokban GDI+"— Előadás másolata:

1 Vizuális programozás Rajzolás Windows Forms alkalmazásokban GDI+

2 Rajzolás GDI+: 2D grafikát támogató osztályok, fontkezelés, képek beillesztése Névtér: System.Drawing Szükséges: –Graphics típusú objektum – ennek a metódusaival történik a rajzolás –Lehetőségek: Paint esemény feldolgozása (Invalidate) bármely eseménynél (Load nem lehet) CreateGraphics() metódus meghívása

3 Jellemzők Grafikus objektumok –Vonalhúzáshoz: Pen típusú objektum, Pens –Kifestéshez: Brush/SolidBrush típusú objektum, Brushes –Betűtípus: Font Eszközfüggetlen rajzolás –képernyő –nyomtató –grafikus állomány Támogatott: jpeg, png, bmp, gif

4

5 Szín megadása Color osztály –Előre definiált színek pl. Color.Blue –Színfelsorolásból pl. Color.FromKnownColor(KnownColor.Azure); –Felhasználó által definiált pl. Color.fromArgb(128,0,0,255); Alpha: az áttetszőséget befolyásolja

6 Kifestőminta megadása Brush –SolidBrush –HatchBrush –LinearGradientBrush –TextureBrush Példaprogram: Áttetszőség

7 Rajzoló és kitöltő metódusok DrawLine( Pen p, int x1, int y1, int x2, int y2 ) DrawRectangle( Pen p, int x, int y, int width, int height ) DrawEllipse(Pen p, int x, int y, int width, int height ) FillRectangle( Brush b, int x, int y, int width, int height ) FillEllipse( Brush b, int x, int y, int width, int height )

8 Rajzoló és kitöltő metódusok DrawLine(Pen p,int x1, int y1, int x2, int y2); DrawArc( Pen p, int x, int y, int width, int height, int kezdőszög, int ívszög ) DrawPie( Pen p, int x, int y, int width, int height, int kezdőszög, int ívszög ) FillPie( Brush b, int x, int y, int width, int height, int kezdőszög, int ívszög ) x y Pozitív szög Példaprogram: Körcikk

9 Problémák Sebesség –Menedzselt DirectX: –SlimDX (http://slimdx.org/) SlimDXhttp://slimdx.org/SlimDXhttp://slimdx.org/ –SharpDX (http://code.google.com/p/sharpdx/) SharpDX –XNA Game Studio XNA Game StudioXNA Game Studio Eltűnő kép –Mindig újrarajzoljuk –Metafájlba lementjük és visszaolvassuk –Képre rajzolás –Dupla pufferelés

10 Példaprogramok GrafikaNemPaintGrafikaPaintKepreRajzolasDuplaPufferHasznalat

11 Koordináta rendszerek World: a rajzoló metódusoknak átadott koordináta értékek ebben vannak myGraphics.DrawLine(myPen, 0, 0, 160, 80) Page: a rajzoló felület (form, vezérlő) által használt koordináta rendszer. Kezdőpontja a kliens terület bal felső sarkában. Device: a megjelenítő eszköz által használt koordináta rendszer (képernyő, papír) Rajzoláskor a rendszer először átalakít PK-ba (World Transformation)majd átalakít DK-ba (Page Transformation)

12 World – logikai k.r. float koordináta értékek Kezdőpontja elmozgatható a Graphics objektum TranslateTransform metódusa segítségével myGraphics.TranslateTransform(100, 50); myGraphics.DrawLine(myPen, 0, 0, 160, 80); Kezdetben a World és Page k.r. kezdőpontja egybeesik

13 Page 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.

14 Device 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.

15 World Transformation A Graphics objektum Transform tulajdonságában van tárolva (mátrix) Átalakító metódusok: –TranslateTransform –ScaleTransform –RotateTransform

16 EredetiTranslT.(70,0)TranslT.(-70,20)ScaleT.(0.5f,1f)

17 myGraphics.Transform = new Matrix(); myGraphics.TranslateTransform(100, 20); myGraphics.RotateTransform(45f); myGraphics. DrawRectangle (Pens.Black, 10, 10, 50, 10); Példapr: WorldKoordRendszMozgatas

18 Page – fizikai k.r. A menüterület is beleesik Page transformation Pen myPen = new Pen(Color.Black,1); myGraphics.PageUnit = GraphicsUnit.Inch; myGraphics.DrawLine(myPen, 0, 0, 2, 1); Pen myPen = new Pen(Color.Black, 1/myGraphics.DpiX); DPI=Dot Per Inch

19 Koordináták Mértékegység –CoordinateSpace.Device – képernyőpont –CoordinateSpace.Page – a koordináták a Graphics.PageUnit-ben megadott egységet használják ( alapértelmezés a GraphicsUnit.Pixel) –CoordinateSpace.World Specifies that coordinates are in the world coordinate context. World coordinates are used in a nonphysical environment, such as a modeling environment. –CoordinateSpace.World Specifies that coordinates are in the world coordinate context. World coordinates are used in a nonphysical environment, such as a modeling environment.

20 GraphicsUnit Display: Specifies the unit of measure of the display device. Typically pixels for video displays, and 1/100 inch for printers. Display: Specifies the unit of measure of the display device. Typically pixels for video displays, and 1/100 inch for printers. Document: Specifies the document unit (1/300 inch) as the unit of measure. Document: Specifies the document unit (1/300 inch) as the unit of measure. Inch: Specifies the inch as the unit of measure. Inch: Specifies the inch as the unit of measure. Millimeter: Specifies the millimeter as the unit of measure. Millimeter: Specifies the millimeter as the unit of measure. Pixel: Specifies a device pixel as the unit of measure. Pixel: Specifies a device pixel as the unit of measure. Point: Specifies a printer's point (1/72 inch) as the unit of measure. Point: Specifies a printer's point (1/72 inch) as the unit of measure. World: Specifies the world coordinate system unit as the unit of measure. World: Specifies the world coordinate system unit as the unit of measure.


Letölteni ppt "Vizuális programozás Rajzolás Windows Forms alkalmazásokban GDI+"

Hasonló előadás


Google Hirdetések