用现代语言实现高效帧缓冲区的简单方法?
我正在寻找一种在 C#、D 或 Java 中实现帧缓冲区的简单方法。允许我使用二维颜色数组并更新单个像素或区域的东西(API 或库)。此外,更新时不会产生大量开销。我知道这可以通过 OpenGL 来完成,但 API 对于我正在做的事情来说似乎太复杂了。
I'm looking for a simple way to implement a framebuffer in C#, D or Java. Something (an API or library) that would allow me to work with a 2d array of colors and update individual pixels or areas. Also, something that doesn't incur large overhead on update. I know that this can be done with OpenGL, but the API seems far too complicated for what I'm doing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试在 .NET 中使用普通的旧
System.Drawing.Bitmap
吗?您可以使用 Bitmap.Lockbits() 来访问位图后面的字节数组并更新它。这比位图上的普通像素操作要高效得多。
MSDN 有一个示例此处,我粘贴自:
Try using a plain old
System.Drawing.Bitmap
in .NET?You could use
Bitmap.Lockbits()
to get access to the byte array behind the bitmap and update it. This is much more efficient than normal pixel operations on the bitmap.MSDN has an example here that I've pasted from:
数组在迭代整个屏幕的如此大量的像素数据时将花费大量时间。最好找到不需要或需要很少迭代的东西。更像是 C 中的指针。
Arrays will take lots of time while iterating through such large amount pixel data for a complete screen. It will be better to find something that doesn't needs or need very less amount of iteration. Something more like pointers in C.
如果您需要的是二维数组,在 C# 中,您可以创建一个 多维数组 让您可以直接访问每个成员。为了提高效率,请尽量避免频繁装箱和拆箱,并且不要频繁分配和释放大内存块,如果做得正确,那么 C# 或 Java 中的此任务效率不会比其他语言低得多。
If what you need is a 2D array, In C# you can create a multidimensional array that gives you direct access to every member. To make this efficient, try to avoid frequent boxing and unboxing and don't allocate and deallocate large memory chunks frequently, and if you do it right there's no reason why this task would be much less efficient in C# or Java than in other languages.