0

I have a 2D array containing Temperature data from a numerically solved heat transfer problem in C#. To visualize the temperature distribution I used the "Bitmap"; Where the lowest Temperature is showed by the color Blue while the hottest is represented by Red! The problem is that it takes too much time to generate the bitmap for a 300x300 image size! While i'm trying to work with larger ones which makes it impossible! Is there any more efficient way to make it work? Any help would be greatly appreciated Here's a little bit of my code and a a generated bitmap: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;
  • Welcome to StackOverflow! Optimization-type questions are probably better suited for the [Code Review SE site](https://codereview.stackexchange.com/) rather than SO. – Das_Geek Oct 24 '19 at 14:55
  • Check [Using Pointers in Image Processing](https://www.codeproject.com/Articles/5129265/Using-Pointers-in-Image-Processing), and [Fast Bitmap modifying using BitmapData and pointers in C#](https://stackoverflow.com/questions/28323448/fast-bitmap-modifying-using-bitmapdata-and-pointers-in-c-sharp), and [Convert a image file in byte pointer data and apply algorithom C#](https://kishordgupta.wordpress.com/2011/02/06/convert-a-image-file-in-byte-pointer-data-and-apply-algorithom-c/). –  Oct 24 '19 at 22:36

0 Answers0