static byte toByte(double v) { var m = (int)(v * 255d); if (m < 0) return 0; if (m > 255) return 255; return (byte)m; }