public static void OutPng(float[] data, int width, int height, string file) { Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb); BitmapData bmpData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); unsafe { uint *dst = (uint *)bmpData.Scan0; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int val = (int)(255 * data[i * width + j]); if (val < 0) { val = 0; } if (val > 255) { val = 255; } dst[i * width + j] = ColorValue.PackValue(val, val, val, 255); } } } bmp.UnlockBits(bmpData); bmp.Save(file, ImageFormat.Png); bmp.Dispose(); }