如何在 C# 中绘制简单的图形? [英] How do I draw simple graphics in C#?

查看:39
本文介绍了如何在 C# 中绘制简单的图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在 C# 中绘制简单的 2D 对象,例如圆、线、正方形等.我怎么做?回到 Turbo C++ 时代,我记得初始化一些图形库来做同样的事情.我需要在 .NET 中做类似的事情吗?3D 对象有什么不同吗?DirectX 之类的东西会让这更容易吗?非常感谢任何指向教程或示例的链接.

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 公开了 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.

可以在 C# 角.

一些需要注意的重要事项:

Some important items to note:

  1. 许多 GDI+ 对象实现了 IDisposable 接口,因此应该包装在 using 块中.确保您遵循适当的处置约定;未能处理 GDI+ 对象可能会给您的应用程序带来非常糟糕的副作用.(.NET 中的 GDI+ 对象对应于它们的底层 Windows API 等效项.)
  2. DirectX 等 API 极其复杂,这是有充分理由的.它们不是为简单的形状而设计的,而是为复杂的、高性能和高度交互的多媒体应用程序设计的.(换言之,通常是游戏.)您可以通过托管 DirectX 接口访问 DirectX,但同样,对于您的直接目的而言,这可能是过度的.
  3. 如果您对使用 DirectX 的更简单方式感兴趣,XNA 是您的最佳选择.然而,这在很大程度上是一个特定于游戏的库,而且很可能是矫枉过正.我参加聚会有点晚了,但根据下面的评论,这根本不再受支持.(这是有道理的;我已经好几年没有听说过它了.)
  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.)

这篇关于如何在 C# 中绘制简单的图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆