简体   繁体   English

如何将像素矩阵直接渲染为wpf元素?

[英]How to render a pixel matrix directly into a wpf element?

So, I'm developing a small program in C# that involves rendering a structure. 因此,我正在用C#开发一个涉及渲染结构的小程序。 I started by using Graphics() but because of certain limitations and for the sake of learning, I created my own 3D engine class (or sort of). 我从使用Graphics()开始,但是由于某些限制并且为了学习,我创建了自己的3D引擎类(或类似的类)。

That class stores and manipulates the pixels in a matrix of: 该类将像素存储和处理为以下矩阵:

public class pixel {
        public Color cor = new Color();
        public int z = Int32.MinValue;
    }

where z is used for visibility check. 其中z用于可见性检查。

Now that I've checked the results (by creating a bitmap file from the matrix), I want to draw and manipulate that matrix directly into a element in my WPF. 现在,我已经检查了结果(通过从矩阵创建位图文件),我想将该矩阵直接绘制并处理到WPF中的元素中。 So i want to know if there's a simple way to do this. 所以我想知道是否有一种简单的方法可以做到这一点。

I'm very fresh on all this, so if there is something that i might be missing please tell me, sometimes i don't know what i should really search for. 我在这一切上都很新鲜,所以如果我可能会缺少一些东西,请告诉我,有时我不知道我应该真正寻找什么。

After trying some different approaches, i ended up storing the data in the matrix in a different way. 在尝试了一些不同的方法之后,我最终以不同的方式将数据存储在矩阵中。

My current solution is to draw directly on a Bitmap (that can be easily passed to a PictureBox control) and at the same time store additional info in a matrix the same size as the Bitmap. 我当前的解决方案是直接在位图上绘制(可以轻松地将其传递给PictureBox控件),同时将其他信息存储在与位图大小相同的矩阵中。

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

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