简体   繁体   English

C#XNA将2D bool数组的给定部分呈现给窗口,该数组代表2种彩色图像

[英]c# XNA render a given section of a 2D bool array representing a 2 color image to the window

Firstly, is my logic about how much space this array will take up correct? 首先,我关于此阵列将占用多少空间的逻辑正确吗?

bool[,] b = new bool[8192 /* 8 * 1024 = 1KB */, 20]; // 20KB

I wish to render a given section of a 2D array to the window. 我希望将2D数组的给定部分渲染到窗口。 The array is of bools and represents a 2 color image. 该数组是布尔型的,代表2色图像。 The image should take up the whole window and each pixel should be sharp\\pixelated as opposed to there being interpolation\\gradients between the pixels centers. 图像应占据整个窗口,并且每个像素应清晰/像素化,而不是像素中心之间存在插值/渐变。

For example (there will ofc be more encapsulation than this): 例如(比这更多的封装):

draw(bool[,] b,
float top_left_x, float top_left_y, float width, float height,
float false_red, float false_green, float false_blue,
float true_red, float true_green, float true_blue)
{
    // what goes here?
}

Is there anything build into c#\\XNA to do this efficiently? c#\\ XNA中是否有任何组件可以有效地做到这一点?

You could do the same thing as opposed here: How to draw 2D pixel-by-pixel in XNA? 您可以执行与此处相反的操作: 如何在XNA中按像素绘制2D像素?

The only thing you have to do is check which color will get into your texture for if it is true or false. 您唯一要做的就是检查哪种颜色会进入您的纹理,如果它是真或假。

You can create a new Texture2D, and then use the SetData function with a array of colors. 您可以创建一个新的Texture2D,然后将SetData函数与颜色数组一起使用。 I haven't tested it, but it should work. 我没有测试过,但是应该可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM