在C#中将温度数据映射到位图

时间:2019-10-24 14:42:23

标签: c# bitmap heatmap numerical-methods

我有一个2D数组,其中包含来自C#中以数值方式解决的传热问题的温度数据。为了可视化温度分布,我使用了“位图”。最低的温度用蓝色表示,而最热的用红色表示! 问题在于,生成300x300图像尺寸的位图需要花费太多时间!当我尝试与较大的打印机一起工作时,这是不可能的! 有没有更有效的方法来使其工作? 任何帮助将不胜感激 这是我的一些代码和一个生成的位图:enter image description here

//RGB Struct
struct RGB
        {
            public Int32 num;
            public int red;
            public int green;
            public int blue;

            public RGB(Int32 num)
            {
                int[] color = new int[3];
                int i = 2;
                while (num > 0)
                {
                    color[i] = num % 256;
                    num = num - color[i];
                    num = num / 256;
                    i--;
                }
                this.red = color[0];
                this.green = color[1];
                this.blue = color[2];
                this.num = (256 * 256) * color[0] + 256 * color[1] + color[2];
            }
        }

//Create Color Array
            Int32 red = 16711680;
            Int32 blue = 255;
            Int32[,] decimalColor = new Int32[Nx, Ny];
            for (int i = 0; i < Nx; i++)
            {
                for (int j = 0; j < Ny; j++)
                {
                    double alpha = (T_new[i, j] - T_min) / (T_max - T_min);
                    double C = alpha * (red - blue);
                    decimalColor[i, j] = Convert.ToInt32(C) + blue;
                }
            }

//Bitmap Result
            Bitmap bmp = new Bitmap(Nx, Ny);
            for (int i = 0; i < Nx; i++)
            {
                for (int j = 0; j < Ny; j++)
                {
                    RGB rgb = new RGB(decimalColor[i, j]);
                    bmp.SetPixel(i,j,Color.FromArgb(rgb.red,rgb.green,rgb.blue));
                }
            }
            pictureBox1.Image = bmp;

0 个答案:

没有答案