void SaveFrame(int framerate) { float rateTime = 1.0f / framerate; if (_frameTime + rateTime < Time.TotalUnscaledf) { _frameTime = Time.TotalUnscaledf; _frameSurface.GetColors(ref buffer); Directory.CreateDirectory(folder); Stream writer = new FileStream($"{folder}/image{_frameIndex:D4}.bmp", FileMode.Create); WriteBitmap(writer, _frameSurface.Width, _frameSurface.Height, buffer); writer.Close(); _frameIndex += 1; } }