首页 > 解决方案 > 在 C# 中的位图上映射温度数据

问题描述

我有一个二维数组,其中包含来自 C# 中数值求解的传热问题的温度数据。为了可视化温度分布,我使用了“位图”;最低温度用蓝色表示,而最高温度用红色表示!问题是生成 300x300 图像大小的位图需要太多时间!虽然我正在尝试与更大的合作,但这是不可能的!有没有更有效的方法让它工作?任何帮助将不胜感激这是我的一些代码和生成的位图:在此处输入图像描述

//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;

标签: c#bitmapheatmapnumerical-methods

解决方案


推荐阅读