1 / 20

Vizuális programozás

Vizuális programozás. Rajzolás Windows Forms alkalmazásokban GDI+. 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:

ezhno
Download Presentation

Vizuális programozás

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. Szín megadása • Color osztály • Előre definiált színekpl. Color.Blue • Színfelsorolásbólpl. Color.FromKnownColor(KnownColor.Azure); • Felhasználó által definiáltpl. Color.fromArgb(128,0,0,255); • Alpha: az áttetszőséget befolyásolja

  5. Kifestőminta megadása • Brush • SolidBrush • HatchBrush • LinearGradientBrush • TextureBrush Példaprogram: Áttetszőség

  6. 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 )

  7. 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 Pozitív szög y Példaprogram: Körcikk

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

  9. Példaprogramok GrafikaNemPaint GrafikaPaint KepreRajzolas DuplaPufferHasznalat

  10. Koordináta rendszerek • World: a rajzoló metódusoknak átadott koordináta értékek ebben vannakmyGraphics.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)

  11. 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 Pagek.r. kezdőpontja egybeesik

  12. 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.

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

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

  15. Eredeti • TranslT.(70,0) • TranslT.(-70,20) • ScaleT.(0.5f,1f)

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

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

  18. 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.WorldSpecifies that coordinates are in the world coordinate context. World coordinates are used in a nonphysical environment, such as a modeling environment. 

  19. GraphicsUnit • 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.  • Inch: Specifies the inch as the unit of measure.  • Millimeter: Specifies the millimeter 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.  • World: Specifies the world coordinate system unit as the unit of measure. 

More Related