我该如何绘制在C#中简单的图形?我该、图形、简单

2023-09-04 00:24:20 作者:-南城荒凉北城伤

我只是想画一样圆,直线,方形等在C#中简单的2D对象。我怎么做?早在涡轮C ++的日子里,我记得初始化一些图形库,做同样的。我需要做的。NET类似的东西?这是任何不同的3D对象?会不会像DirectX的使这更容易?任何链接到教程或样品多少AP preciated。

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 doing the same. Do I need to do something similar in .NET? Is it any different for 3D objects? Will things like DirectX make this any easier? Any links to tutorials or samples much appreciated.

推荐答案

正如其他人说,检查出的 System.Drawing中。 (我只是重复的完整性。)System.Drawing中公开 GDI + windows画图库到应用程序。

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.

一个很好的教程,让你跳开始System.Drawing中和GDI +可以在找到C#角。

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

一些重要的项目要注意的:

Some important items to note:

在许多GDI +对象实现IDisposable接口,因此应放在使用块。确保你遵循适当的处置公约;未处置的GDI +对象可能会导致真正讨厌的副作用你的应用程序。 (在.NET GDI +对象对应于它们的底层Windows API的等价物。) API,如DirectX是极其复杂的,有很好的理由。他们不是简单的形状设计的,而是复杂的,高度高性能和高交互性的多媒体应用。 (换句话说,游戏,典型的。)您可以通过托管DirectX接口访问DirectX的,但是,它可能是矫枉过正的直接目的。 如果你有兴趣在一个简单的方法与DirectX工作, XNA 是要走的路。然而,这是一个很有游戏专用库,并再次可能是矫枉过正。 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.) 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. 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.