private void Save(string colorName, System.Drawing.Color color) { float hue = color.GetHue(); float brightness = color.GetBrightness(); File.AppendAllText(@"c:\users\brush\desktop\" + colorName + ".csv", string.Format("{0},{1},{2},{3},{4}\r\n", color.R, color.G, color.B, hue, brightness)); }
internal static ColorHSL FromSystemDrawingColor(System.Drawing.Color color) { ColorHSL rv = new ColorHSL { Hue = color.GetHue() / 360.0, Saturation = color.GetSaturation(), Lightness = color.GetBrightness() }; return rv; }
public static bool IsCloseColors(System.Drawing.Color x, System.Drawing.Color y) { double colorDelta = GetColorDelta(x, y); return ((colorDelta < 100.0) || ((colorDelta < 210.0) && (Math.Abs((float) (x.GetBrightness() - y.GetBrightness())) < 0.1))); }
public static double ColorToBrightness(System.Drawing.Color c) { return c.GetBrightness(); }
/// <summary> /// This method draws a cross at the given position. /// </summary> /// <param name="image">The input image.</param> /// <param name="point">The position of the cross.</param> /// <param name="size">The size of the cross.</param> /// <param name="color">The color of the cross.</param> /// <param name="thickness">The thickness of the cross.</param> private void DrawCross(Image<Gray, byte> image, Point point, int size, System.Drawing.Color color, int thickness) { // Convert to System.Drawing.Point until EMGU updates its library System.Drawing.Point p1 = new System.Drawing.Point((int)point.X - (int)(size / 2), (int)point.Y); System.Drawing.Point p2 = new System.Drawing.Point((int)point.X + (int)(size / 2), (int)point.Y); image.Draw(new LineSegment2D(p1, p2), new Gray(color.GetBrightness()), thickness); System.Drawing.Point p3 = new System.Drawing.Point((int)point.X, (int)point.Y - (int)(size / 2)); System.Drawing.Point p4 = new System.Drawing.Point((int)point.X, (int)point.Y + (int)(size / 2)); image.Draw(new LineSegment2D(p3, p4), new Gray(color.GetBrightness()), thickness); }
private bool isColorClose(System.Drawing.Color color1, System.Drawing.Color color2, int tolerance) { if (Math.Abs(color1.GetHue() - color2.GetHue()) % (360 - tolerance) < tolerance) if (Math.Abs(color1.GetSaturation() - color2.GetSaturation()) % (360 - tolerance) < tolerance) if (Math.Abs(color1.GetBrightness() - color2.GetBrightness()) % (360 - tolerance) < tolerance) return true; return false; }
private static System.Windows.Forms.DataGridViewCellStyle CalculateCellStyle(System.Windows.Forms.DataGridViewCellStyle baseStyle, System.Drawing.Color color) { int num = (color.get_R() > 0x33) ? ((int) (color.get_R() - 0x33)) : ((int) 0); int num2 = (color.get_G() > 0x33) ? ((int) (color.get_G() - 0x33)) : ((int) 0); int num3 = (color.get_B() > 0x33) ? ((int) (color.get_B() - 0x33)) : ((int) 0); System.Drawing.Color color2 = System.Drawing.Color.FromArgb(num, num2, num3); baseStyle.set_BackColor(color); baseStyle.set_ForeColor((color.GetBrightness() > 0.5) ? System.Drawing.Color.Black : System.Drawing.Color.White); baseStyle.set_SelectionBackColor(color2); baseStyle.set_SelectionForeColor((color2.GetBrightness() > 0.5) ? System.Drawing.Color.Black : System.Drawing.Color.White); return baseStyle; }