void colorChanged() { var hsv = new ColorHSV((int)nudH.Value, (int)nudS.Value, (int)nudV.Value); refreshColorPanel(hsv); }
public static ColorRGB HsvToRgb(ColorHSV hsv) { if (hsv.H == 360) { hsv.H = 359; // 360为全黑,原因不明 } float R = 0f, G = 0f, B = 0f; if (hsv.S == 0) { return(new ColorRGB(hsv.V, hsv.V, hsv.V)); } float S = hsv.S * 1.0f / 255, V = hsv.V * 1.0f / 255; int H1 = (int)(hsv.H * 1.0f / 60), H = hsv.H; float F = H * 1.0f / 60 - H1; float P = V * (1.0f - S); float Q = V * (1.0f - F * S); float T = V * (1.0f - (1.0f - F) * S); switch (H1) { case 0: R = V; G = T; B = P; break; case 1: R = Q; G = V; B = P; break; case 2: R = P; G = V; B = T; break; case 3: R = P; G = Q; B = V; break; case 4: R = T; G = P; B = V; break; case 5: R = V; G = P; B = Q; break; } R = R * 255; G = G * 255; B = B * 255; while (R > 255) { R -= 255; } while (R < 0) { R += 255; } while (G > 255) { G -= 255; } while (G < 0) { G += 255; } while (B > 255) { B -= 255; } while (B < 0) { B += 255; } return(new ColorRGB((int)R, (int)G, (int)B)); }