How do I draw simple graphics in C#?

后端 未结 9 819
伪装坚强ぢ
伪装坚强ぢ 2020-12-10 02:33

I just want to draw simple 2D objects like circle, line, square etc in C#. How do I do that? Back in the Turbo C++ days I remember initializing some graphics library for doi

相关标签:
9条回答
  • 2020-12-10 02:35

    Look at the System.Drawing Namespace

    0 讨论(0)
  • 2020-12-10 02:40

    As others have said, check out System.Drawing. (I'm only repeating that for completeness.) System.Drawing exposes the GDI+ Windows drawing library to your application.

    A good tutorial to get you jump-started with System.Drawing and GDI+ can be found at C# Corner.

    Some important items to note:

    1. Many GDI+ objects implement the IDisposable interface, and therefore should be wrapped in using blocks. Be sure you follow the appropriate disposal conventions; failing to dispose GDI+ objects can result in really nasty side effects for your app. (GDI+ objects in .NET correspond to their underlying Windows API equivalents.)
    2. APIs such as DirectX are extremely complex, and for good reason. They're designed not for simple shapes, but rather for complex, highly-performant and highly-interactive multimedia applications. (In other words, games, typically.) You can access DirectX through the Managed DirectX interfaces, but again, it's probably overkill for your direct purposes.
    3. If you are interested in an easier way to work with DirectX, XNA is the way to go. However, this is very much a gaming-specific library, and again is likely to be overkill. I'm a bit late to the party, but according to the comments below, this is no longer supported at all. (This makes sense; I haven't heard anything about it in years.)
    0 讨论(0)
  • 2020-12-10 02:40

    Look for Managed Direct3D graphics API in .NET Source

    0 讨论(0)
  • 2020-12-10 02:42

    The best way to implement 2D Graphics in C# Windows Forms (also VB.Net) is using CefSharp and Canvas API via JavaScript language. Canvas is way better and faster than clunky GDI+

    0 讨论(0)
  • 2020-12-10 02:51

    Check out the System.Drawing namespace: http://msdn.microsoft.com/en-us/library/system.drawing.aspx

    0 讨论(0)
  • 2020-12-10 02:56

    Read about GDI, GDI+, System.Drawing namespace, for example here.
    DirectX is not something you would use to draw simple shapes, rather render complicated 3D stuff, also, using DX Api under C# is a bit trickier (although not that hard).

    0 讨论(0)
提交回复
热议问题