C# 或 C++ - 有关 Windows 图形概述的好资源 - 2D,直接绘制像素
我一直在开发这个奇怪的小生活模拟程序,其中涉及二维数组中的数据。这从来不应该是一件大事,我最初通过将其逐像素写入外部位图来查看它的一些快照,然后打开并查看。这不会给我任何形式的屏幕实时更新。这是一种可怕的方法,在尝试直接在窗口中实现绘制时,我想第一次就正确有效地完成此操作。
我做了一些搜索,发现 bitblt ,这将让我一次绘制一个完整的矩形,但我所有的图形经验都仅限于 WPF 之类的东西,很多术语我都记不清了。我不知道我的数据应该是什么格式才能将其作为位图传递给此函数。在阅读 msdn 时,我发现了诸如 DC 之类的参考资料,还有更多我尚未了解的内容。
我不需要了解很多有关 Windows 图形 API 或 .NET 绘图框架的知识。我不想学一堆DirectX。我想制作一个特定尺寸的窗口,并且希望能够根据我的需要设置每个像素的 RGB 值。没有绘图形状或任何东西,只有像素。但我也不想一次处理一个像素,每个像素都有一个单独的系统调用,因为即使像我这样蹩脚的程序员也知道这是多么低效。有谁知道是否有一个好的资源可以对 Windows 中的图形进行简单的解释并让我这样做? MSDN 非常适合查找信息,但如果您想从头开始学习某些东西,那就有点太多了。
C# 更可取,因为 lifesim 是用它写的,但如果有充分的理由,我对用 C++ 重写它没有任何疑虑。
I have this odd little lifesim program I've been working on that involves data in a 2d array. This was never supposed to be a big thing, and I initially looked at a few snapshots of it by just writing it out to an external bitmap, pixel by pixel, which I then open and look at. This doesn't give me any sort of live update to the screen. This is a horrible way to do this, and in trying to implement drawing this directly in a window, I want to do this correct and efficiently the first time.
I did some searching and found bitblt, which will let me draw a whole rectangle at a time, but all of my graphics experience being limited to things like WPF, a lot of the terminology is lost on me. I don't know what format my data should be in order to hand it to this function as a bitmap. In reading around msdn I find references to things like DC, etc, more things I haven't yet learned about.
I don't need to know lots about Windows graphics API or .NET's drawing framework. I don't want to learn a bunch of DirectX. I want to make a Window of a specific dimension and I want to be able to set the RGB value of each of those pixels as I see fit. No drawings shapes or anything, just pixels. But I also don't want to do it one pixel at a time, a separate system call for each, because even a lame programmer like myself knows how terribly inefficient that is. Does anyone know if a good resource that will give a simple explanation of graphics in Windows and will let me do this? MSDN is great for looking things up, but it's a bit much if you're trying to learn something from scratch.
C# is preferable because the lifesim in written in it, but I don't have any qualms about rewriting it in C++ if there's a good reason for it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用 WriteableBitmap 类WPF 并看看它是否符合您的目的。
教程
您所要做的就是保留2D 数组中的数据并将其写入 WriteableBitmap。将 WriteableBitmap 设置为 WPF Image 的图像源即可完成。
如果您需要示例,请告诉我。
You could try the WriteableBitmap class in WPF and see if it fits your purposes.
A tutorial
All you would have to do is keep the data in the 2D array and write it to the WriteableBitmap. Set the WriteableBitmap as the image source of a WPF Image and you're done.
Let me know if you need an example.
您可能想要做的是使用 LockBits 锁定图像数据,然后将图像作为数组进行操作。这是 Bob Powell 的精彩教程:
https://web.archive.org/web/20121203144033/http://www.bobpowell.net/lockingbits.htm
否则,如果速度不是问题,您可以使用 GetPixel 和 SetPixel方法。虽然这些速度非常慢,但可以在托管环境中运行。
What you probably want to do is use LockBits to lock up your image data, and then manipulate your image as an array. Here's a great tutorial by Bob Powell:
https://web.archive.org/web/20121203144033/http://www.bobpowell.net/lockingbits.htm
Otherwise, if speed is not a concern, you can use the GetPixel and SetPixel methods. These are horribly slow though, but will work in a managed environment.