static byte ScaleIntToByte(int fragmentLength, int max, int min) { double result = (fragmentLength - min) * 255 / (double)(max - min); if (result > 255) return 255; if (result < 0) return 0; return (byte)result; }