private Image CreateImage(double[,] hitMatrix) { _1Dimage = new double[NUM_PIXELS_SIDE * NUM_PIXELS_SIDE]; double min = hitMatrix.Cast <double>().Min(); double max = hitMatrix.Cast <double>().Max(); double range = max - min; byte v; System.Buffer.BlockCopy(hitMatrix, 0, _1Dimage, 0, NUM_PIXELS_SIDE * NUM_PIXELS_SIDE); //DisplaySNR(Elementary.CalculateSNR(min, max, _1Dimage)); DisplayERROR(Elementary.CalculateError(NUM_PIXELS_SIDE)); Bitmap bitmap = new Bitmap(hitMatrix.GetLength(0), hitMatrix.GetLength(1)); BitmapData bidmapdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); // This is much faster than calling Bitmap.SetPixel() for each pixel. unsafe { byte *pointer = (byte *)bidmapdata.Scan0; for (int colIterator = 0; colIterator < bidmapdata.Height; colIterator++) { for (int rowIterator = 0; rowIterator < bidmapdata.Width; rowIterator++) { v = (byte)(255 * (hitMatrix[rowIterator, bidmapdata.Height - 1 - colIterator] - min) / range); pointer[0] = v; pointer[1] = v; pointer[2] = v; pointer[3] = (byte)255; pointer += 4; } pointer += (bidmapdata.Stride - (bidmapdata.Width * 4)); } } bitmap.UnlockBits(bidmapdata); return(bitmap); }