Your SlideShare is downloading. ×
Graphics
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Graphics

514

Published on

C# Graphics

C# Graphics

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
514
On Slideshare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. C# .NET Graphics
    Extra – not tested
    Required for assignment 1
  • 2. What will we be learning?
    Surface, pen and brush
    Draw Lines
    Draw Rectangles
    Draw Polygons
    Draw Text
  • 3. Basic - Graphics
    (1) we need to have a Graphics instance (similar to a surface)
  • 4. Basic
    Declare
    Graphics mySurface;
  • 5. Basic
    Create
    Graphics mySurface;
    mySurface = this.CreateGraphics();
  • 6. Basic - Pen
    (2) To draw lines or outlines of shapes, we need a Pen
  • 7. Basic - Pen
    Declare
    Pen pen1;
  • 8. Basic - Pen
    Create
    2 parameters
    - Color
    - thickness
    Pen pen1;
    pen1 = new Pen(Color.Blue, 1.0f);
  • 9. Basic - Brush
    (3) To fill inside shapes, we need a Brush
  • 10. Basic - Brush
    Declare
    Types of brush
    SolidBrush
    HatchBrush
    LinearGradientBrush
    PathGradientBrush
    TextureBrush
    SolidBrush brush1;
  • 11. Basic - Brush
    Create
    SolidBrush brush1;
    brush1 = new SolidBrush(Color.Green);
  • 12. Basic - Brush
    Types of brush
    SolidBrush
    HatchBrush
    LinearGradientBrush
    PathGradientBrush
    TextureBrush
  • 13. Draw Lines
    > New Solution: SpfGraphics
    > Select Form1.cs, select design view
    > select events and double click “Paint” event
  • 14. Draw Lines
  • 15. Draw Lines
  • 16. Output
  • 17. Using points & DrawLines
    Continue in Form1_Paint
  • 18. Output
    surface1.DrawLine(pen1, pt1, pt3);
    surface1.DrawLines(pen1, points);
  • 19. Draw Rectangle
    Continue in Form1_Paint
  • 20. Draw Rectangle
  • 21. Fill Shape
    Continue in Form1_Paint
  • 22. Fill Shape
  • 23. Draw Polygon
    Continue in Form1_Paint
  • 24. Draw Polygon
  • 25. Draw Text
    Continue in Form1_Paint
  • 26. Draw Text
  • 27. Try it yourself: drawing cross for mousedown
    VIDEO
  • 28. Try it yourself!
    Hint: use the mousedown event
    Hint: use points (e.X-5, e.Y-5) , (e.X+5, e.Y+5), (e.X+5, e.Y-5) , (e.X-5, e.Y+5)
  • 29. Possible solution
  • 30. Draw fix line follow mouse
  • 31. Draw fix line follow mouse
    New project “lineFollowMouse”
  • 32. Draw fix line follow mouse
    // Get the mouse position
  • 33. Demo: flexi line follow mouse
    VIDEO
  • 34. Flexi line follow mouse
    // Get the mouse position
  • 35. Demo: Simple pixel drawing
    VIDEO
  • 36. Simple pixel drawing
    New project: SimplePixelDrawing
  • 37. Simple pixel drawing
  • 38. Simple pixel drawing
  • 39. Simple pixel drawing
    to continue next page
  • 40. Simple pixel drawing
    continue from previous page
  • 41. Summary
    Surface, pen and brush
    Draw Lines
    Draw Rectangles
    Draw Polygons
    Draw Text

×