private static void InnerBrushChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ColorPicker cp = d as ColorPicker; SolidColorBrush curBrush = (SolidColorBrush)e.NewValue; SolidColorBrush oldBrush = (SolidColorBrush)e.OldValue; if (curBrush.Color.A == oldBrush.Color.A && curBrush.Color.R == oldBrush.Color.R && curBrush.Color.G == oldBrush.Color.G && curBrush.Color.B == oldBrush.Color.B) { return; } HlsColor hls = HSL.RgbToHls(curBrush.Color); cp.slider1.Value = curBrush.Color.A; cp.slider2.Value = curBrush.Color.R; cp.slider3.Value = curBrush.Color.G; cp.slider4.Value = curBrush.Color.B; double posX = hls.H * 280 / 360.0 - 5; double posY = (1 - hls.S) * 280 - 5; cp.customCanvas.Background = curBrush; }
private Color GetMouseOverColor(Color c) { var hls = new HlsColor(c); hls.Lighten(0.25f); return(hls.Color); }
private static void ColorSample(HtmlRenderer html, string s) { int c = ColorParser.Parse(s); Parameters style = new Parameters(); if (c == ColorParser.InvalidColor) { style["color"] = "#000000"; style["background-color"] = "#ffffff"; } else { s = "#" + c.ToString("x6"); style["color"] = s; style["background-color"] = s; HlsColor hls = ColorTransform.RgbToHls(ColorTransform.IntToRgb(c)); if (hls.L > 800) { style["border"] = "1px solid #808080"; } } html.Add("<div"); html.Style(style); html.Add(">"); html.Add(String.IsNullOrEmpty(s) ? "X" : "?"); html.Add("</div>"); }
public static IHlsColor MakeHLS(MakeBasicColors.basicColorEnum basicColorEnum_0) { IHlsColor hlsColorClass = new HlsColor() { RGB = MakeBasicColors.MakeRGB(basicColorEnum_0).RGB }; return(hlsColorClass); }
private void LuminanceSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { Color c = this.Color; HlsColor hls = new HlsColor(c); hls.Luminance = (float)LuminanceSlider.Value; Color nc = hls.Color; this.Color = Color.FromArgb(c.A, nc.R, nc.G, nc.B); }
private static void OnColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Color c = (Color)e.NewValue; HlsColor hls = new HlsColor(c); ColorPickerPanel panel = (ColorPickerPanel)d; panel.LuminanceSlider.Value = hls.Luminance; panel.TransparencySlider.Value = (double)c.A / 255.0; panel.OnColorChanged(); }
public static Color ConvertHslToRgb(HlsColor hlsColor) { // Initialize result var rgbColor = new Color(); /* If S = 0, that means we are dealing with a shade * of gray. So, we set R, G, and B to L and exit. */ // Special case: Gray if (hlsColor.S == 0) { rgbColor.R = (byte)(hlsColor.L * 255); rgbColor.G = (byte)(hlsColor.L * 255); rgbColor.B = (byte)(hlsColor.L * 255); rgbColor.A = (byte)(hlsColor.A * 255); return(rgbColor); } double t1; if (hlsColor.L < 0.5) { t1 = hlsColor.L * (1.0 + hlsColor.S); } else { t1 = hlsColor.L + hlsColor.S - (hlsColor.L * hlsColor.S); } var t2 = 2.0 * hlsColor.L - t1; // Convert H from degrees to a percentage var h = hlsColor.H / 360; // Set colors as percentage values var tR = h + (1.0 / 3.0); var r = SetColor(t1, t2, tR); var tG = h; var g = SetColor(t1, t2, tG); var tB = h - (1.0 / 3.0); var b = SetColor(t1, t2, tB); // Assign colors to Color object rgbColor.R = (byte)(r * 255); rgbColor.G = (byte)(g * 255); rgbColor.B = (byte)(b * 255); rgbColor.A = (byte)(hlsColor.A * 255); // Set return value return(rgbColor); }
public ChartColumn(ChartValue cv, NumberFormatInfo nfi, Color c1, double colWidth, double availableHeight, double range) { this.availableHeight = availableHeight; if (range == 0) { range = availableHeight; } this.range = range; vtext = new TextBlock(); Binding binding = new Binding(); binding.Source = this; binding.Path = new PropertyPath("ColumnValue"); binding.Converter = new NumberConverter(nfi); vtext.SetBinding(TextBlock.TextProperty, binding); vtext.HorizontalAlignment = HorizontalAlignment.Center; r = new Rectangle(); r.Width = colWidth; r.Height = 0; r.RadiusX = r.RadiusY = 2; HlsColor hls = new HlsColor(c1); hls.Lighten(.3f); Color c2 = hls.Color; hls = new HlsColor(c1); hls.Darken(.3f); Color stroke = hls.Color; r.Stroke = new SolidColorBrush(stroke); r.StrokeThickness = 1; r.Fill = new LinearGradientBrush(c1, c2, new Point(0, 0), new Point(0, 1)); TextBlock label = new TextBlock(); label.Text = cv.Label; label.HorizontalAlignment = HorizontalAlignment.Center; this.Children.Add(vtext); this.Children.Add(r); this.Children.Add(label); this.value = cv; this.SetValue(ColumnValueProperty, cv.Value); }
Brush GetHighlightBrush() { if (_normal == null) { this._normal = this.Background; } if (_highlight == null) { SolidColorBrush temp = this._normal as SolidColorBrush; if (temp != null) { var hls = new HlsColor(temp.Color); hls.Lighten(0.25f); _highlight = new SolidColorBrush(hls.Color); } else { _highlight = new SolidColorBrush(Color.FromArgb(0xff, 0x3E, 0x3E, 0x40)); } } return(_highlight); }
Brush GetPressedBrush() { if (_normal == null) { this._normal = this.Background; } if (_pressed == null) { SolidColorBrush temp = this._normal as SolidColorBrush; if (temp != null) { var hls = new HlsColor(temp.Color); hls.Darken(0.25f); _pressed = new SolidColorBrush(hls.Color); } else { _pressed = new SolidColorBrush(Color.FromArgb(0xff, 0x00, 0x7A, 0xCC)); } } return(_highlight); }
private static void ColorInfo(HtmlRenderer html, string s) { if (String.IsNullOrEmpty(s)) { html.Text("Color not specified"); return; } int c = ColorParser.Parse(s); if (c == ColorParser.InvalidColor) { html.Text("Invalid color string"); return; } html.Text("WEB #" + c.ToString("x6")); Color cc = Color.FromArgb(c); html.Text(String.Format(", RGB({0},{1},{2}),", ((double)cc.R / 255f).ToString("######0.0##"), ((double)cc.G / 255f).ToString("######0.0##"), ((double)cc.B / 255f).ToString("######0.0##"))); HlsColor hls = ColorTransform.RgbToHls(cc); html.Add("<br>"); html.Text(String.Format("HLS({0},{1},{2})", ((double)hls.H / 100f).ToString("######0.0##"), ((double)hls.L / 1000f).ToString("######0.0##"), ((double)hls.S / 1000f).ToString("######0.0##"))); LabColor lab = ColorTransform.RgbToLab(cc); html.Text(String.Format(", LAB({0},{1},{2})", lab.L.ToString("######0.0##"), lab.A.ToString("######0.0##"), lab.B.ToString("######0.0##"))); }
private void AddRow(int index, ChartDataValue dv) { Row ui = null; if (LegendGrid.RowDefinitions.Count <= index) { LegendGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }); } if (this.elements.Count > index) { // reuse previous elements! ui = this.elements[index]; } else { ui = new Row(); if (dv.Color.HasValue) { var c = dv.Color.Value; ToggleButton colorSwatch = new ToggleButton(); colorSwatch.Template = swatchTemplate; colorSwatch.Margin = new Thickness(2); colorSwatch.Width = 16; colorSwatch.Height = 16; colorSwatch.DataContext = dv; ui.button = colorSwatch; } TextBlock label = new TextBlock() { Text = dv.Label, Margin = new Thickness(5, 2, 5, 2) }; ui.label = label; TextBlock total = new TextBlock() { Text = dv.Value.ToString("C0"), Margin = new Thickness(5, 2, 5, 2), HorizontalAlignment = HorizontalAlignment.Right }; ui.value = total; this.elements.Add(ui); } ui.item = dv; if (ui.button != null) { var c = dv.Color.Value; HlsColor hls = new HlsColor(c); ui.button.Background = new SolidColorBrush(c); if (hls.Luminance < 0.5) { ui.button.Foreground = Brushes.White; } else { ui.button.Foreground = Brushes.Black; } ui.button.DataContext = dv; Grid.SetRow(ui.button, index); Grid.SetColumn(ui.button, 0); LegendGrid.Children.Add(ui.button); ui.button.Checked -= OnColorSwatchToggled; ui.button.Unchecked -= OnColorSwatchToggled; ui.button.IsChecked = dv.Hidden; ui.button.Checked += OnColorSwatchToggled; ui.button.Unchecked += OnColorSwatchToggled; } ui.label.Text = dv.Label; Grid.SetRow(ui.label, index); Grid.SetColumn(ui.label, 1); LegendGrid.Children.Add(ui.label); ui.value.Text = dv.Value.ToString("C0"); Grid.SetRow(ui.value, index); Grid.SetColumn(ui.value, 2); LegendGrid.Children.Add(ui.value); }
void PopulateTheChart(StackPanel legend) { selectedSeries = null; foreach (ChartSeries s in data.AllSeries) { if (s.Values.Count > 0) { PathGeometry path = new PathGeometry(); PathFigure figure = new PathFigure(); path.Figures.Add(figure); figure.IsClosed = true; double x = 0; double min = s.Minimum; double max = s.Maximum; bool flip = false; if (s.Flipped) { double temp = max; max = -min; min = -temp; flip = true; } graphMin = Math.Min(graphMin, min); graphMax = Math.Max(graphMax, max); figure.StartPoint = new Point(0, 0); // Add the grid column labels along the bottom row. foreach (ChartValue cv in s.Values) { double v = cv.Value; if (flip) { v = -v; } figure.Segments.Add(new LineSegment(new Point(x, v), true)); x++; } if (x > 0) { x--; } figure.Segments.Add(new LineSegment(new Point(x, 0), true)); Path shape = new Path(); shape.Data = path; geometries.Add(path); Color c = (Color)s.Category.WpfColor; HlsColor hls = new HlsColor(c); hls.Darken(.25f); shape.Fill = new SolidColorBrush(Color.FromArgb(0xA0, c.R, c.G, c.B)); shape.Stroke = new SolidColorBrush(hls.Color); shape.StrokeThickness = 1; this.Children.Add(shape); graphWidth = Math.Max(graphWidth, x); AddLengenEntry(legend, s, shape); } } }
public static void RenderPaletteItem(HtmlRenderer html, PaletteItem item, string key, bool black) { html.Add("\r\n<tr"); html.Add("valign", "middle"); html.Add("bgcolor", black ? "#000000" : "#ffffff"); html.Add("><td align=\"center\""); Parameters style = new Parameters(); style["border-bottom"] = "2px solid #909090"; style["padding"] = "8px"; style["font-size"] = "small"; style["color"] = black ? "#c0c0c0" : "#404040"; html.Style(style); html.Add(">"); if (search.showThumblains) { Parameters par = new Parameters(); par["Id"] = item.Id.ToString(); par["Key"] = key; html.Image("handler.ashx?q=thumbnail&t=" + HttpUtility.UrlEncode(par.Serialize()), "Palette source image thumbnail"); } else { html.Text("No image"); } html.Add("</td>\r\n<td"); html.Add("align", "left"); html.Style(style); html.Add(">"); html.Add("<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\"><tr><td align=\"left\""); style.Clear(); style["padding"] = "8px"; style["border-bottom"] = "1px solid #909090"; html.Style(style); html.Add(">"); if (item.Colors.Length > 0) { html.Add("<table border=\"0\" cellpadding=\"0\" cellspacing=\"4\"><tr valign=\"middle\">"); style.Clear(); style["width"] = "96px"; style["height"] = "56px"; style["padding-top"] = "40px"; style["text-align"] = "center"; for (int i = 0; i < item.Colors.Length; i++) { html.Add("<td><div"); string c = "#" + (item.Colors[i].ToArgb() & 0xffffff).ToString("x6"); style["background-color"] = c; HlsColor hls = ColorTransform.RgbToHls(item.Colors[i]); style["color"] = hls.L > 500 ? "#202020" : "#f0f0f0"; html.Style(style); html.Add(">"); html.Text(c); html.Add("</div></td>"); } html.Add("</tr></table>"); } else { html.Text("Empty color list"); } html.Add("</td></tr>\r\n<tr><td"); style.Clear(); style["font-size"] = "medium"; style["padding"] = "8px"; style["color"] = black ? "#c0c0c0" : "#404040"; html.Style(style); html.Add(">"); html.Text(item.Title); html.Add("</td></tr></table></td></tr>"); }
/// <summary> /// Converts a color from HLS to RGB color space. /// </summary> /// <param name="hlsColor">The input color.</param> /// <returns>An RGB color corresponding to the input color.</returns> private static RgbColor HlsToRgb(HlsColor hlsColor) { Debug.Assert(hlsColor.Lightness >= 0 && hlsColor.Lightness <= 1, "Lightness must be between 0 and 1."); Debug.Assert(hlsColor.Saturation >= 0 && hlsColor.Saturation <= 1, "Saturation must be between 0 and 1."); // Check for the achromatic (gray) case. float red, green, blue; if ((float)hlsColor.Saturation == 0.0) { red = green = blue = hlsColor.Lightness; } else { // Shift hue into the [0, 6) interval. float hue = (float)((hlsColor.Hue - Math.Floor(hlsColor.Hue)) * 6); float m2; if (hlsColor.Lightness <= 0.5f) m2 = hlsColor.Lightness * (1 + hlsColor.Saturation); else m2 = hlsColor.Lightness + hlsColor.Saturation - hlsColor.Lightness * hlsColor.Saturation; float m1 = 2 * hlsColor.Lightness - m2; red = HlsValue(m1, m2, hue + 2); green = HlsValue(m1, m2, hue); blue = HlsValue(m1, m2, hue - 2); } Debug.Assert(red >= 0 && red <= 1, "Output red should be between 0 and 1."); Debug.Assert(green >= 0 && green <= 1, "Output green should be between 0 and 1."); Debug.Assert(blue >= 0 && blue <= 1, "Output blue should be between 0 and 1."); return new RgbColor(hlsColor.Alpha, red, green, blue); }
private static void SetColor(ElementStylesBase ElementStylesBase, SolidColorBrush _1, string keyname) { //var _color1 = HexToBrush.ToColor("#409EFF"); //var _color2 = HexToBrush.ToColor("#D9ECFF"); //var _color3 = HexToBrush.ToColor("#ECF5FF"); //var _color4 = HexToBrush.ToColor("#66B1FF"); //var _color5 = HexToBrush.ToColor("#C6E2FF"); //HlsColor hsv1 = AyColorHelper.ConvertRgbToHsl(_color1); //HlsColor hsv2 = AyColorHelper.ConvertRgbToHsl(_color2); //HlsColor hsv3 = AyColorHelper.ConvertRgbToHsl(_color3); //HlsColor hsv4 = AyColorHelper.ConvertRgbToHsl(_color4); //HlsColor hsv5 = AyColorHelper.ConvertRgbToHsl(_color5); //Console.WriteLine((hsv2.H - hsv1.H).ToString() + "\t" + (hsv2.S - hsv1.S).ToString() + "\t" + (hsv2.L - hsv1.L).ToString()); //Console.WriteLine((hsv3.H - hsv1.H).ToString() + "\t" + (hsv3.S - hsv1.S).ToString() + "\t" + (hsv3.L - hsv1.L).ToString()); //Console.WriteLine((hsv4.H - hsv1.H).ToString() + "\t" + (hsv4.S - hsv1.S).ToString() + "\t" + (hsv4.L - hsv1.L).ToString()); //Console.WriteLine((hsv5.H - hsv1.H).ToString() + "\t" + (hsv5.S - hsv1.S).ToString() + "\t" + (hsv5.L - hsv1.L).ToString()); HlsColor hsl = AyColorHelper.ConvertRgbToHsl(_1.Color); var _a2 = hsl.H - 0.471204188481693; if (_a2 < 0) { _a2 = 0; } var _a3 = hsl.L + 0.3; if (_a3 > 1) { _a3 = 1; } HlsColor h = new HlsColor(); h.A = hsl.A; h.H = _a2; h.L = _a3; h.S = hsl.S; Color l1Color = AyColorHelper.ConvertHslToRgb(h); var _a4 = hsl.H + 1.10774317993938; if (_a4 > 360) { _a4 = 360; } var _a5 = hsl.L + 0.337254901960784; if (_a5 > 1) { var _122 = _a5 - 1 + 0.03; _a5 = _a5 - _122; } HlsColor h2 = new HlsColor(); h2.A = hsl.A; h2.H = _a4; h2.L = _a5; h2.S = hsl.S; Color l2Color = AyColorHelper.ConvertHslToRgb(h2); ElementStylesBase.EnsureResource(keyname + "1", new SolidColorBrush(l1Color)); ElementStylesBase.EnsureResource(keyname + "2", new SolidColorBrush(l2Color)); var _a6 = hsl.H + 0.117031105635988; if (_a6 > 360) { _a6 = 360; } var _a7 = hsl.L + 0.0745098039215686; if (_a7 > 1) { _a7 = 1; } HlsColor h3 = new HlsColor(); h3.A = hsl.A; h3.H = _a6; h3.L = _a7; h3.S = hsl.S; Color l3Color = AyColorHelper.ConvertHslToRgb(h3); ElementStylesBase.EnsureResource(keyname + "3", new SolidColorBrush(l3Color)); var _a8 = hsl.H + 0.226470230122999; if (_a8 > 360) { _a8 = 360; } var _a9 = hsl.S - 0.225225225225225; if (_a9 < 0) { _a9 = 0; } var _a10 = hsl.L - 0.0607843137254902; if (_a10 < 0) { _a10 = 0; } HlsColor h4 = new HlsColor(); h4.A = hsl.A; h4.H = _a8; h4.L = _a10; h4.S = _a9; Color l4Color = AyColorHelper.ConvertHslToRgb(h4); ElementStylesBase.EnsureResource(keyname + "4", new SolidColorBrush(l4Color)); //边框色 var _a11 = hsl.H + 0.0551116009920349; if (_a11 > 360) { _a11 = 360; } var _a12 = hsl.L + 0.262745098039216; if (_a12 > 1) { _a12 = 1; } HlsColor h5 = new HlsColor(); h5.A = hsl.A; h5.H = _a11; h5.L = _a12; h5.S = hsl.S; Color l5Color = AyColorHelper.ConvertHslToRgb(h5); ElementStylesBase.EnsureResource(keyname + "5", new SolidColorBrush(l5Color)); //Console.WriteLine("<" + keyname + "1" + " value=\"" + l1Color.ToString() + "\" Des=\"自动计算\"/>"); //Console.WriteLine("<" + keyname + "2" + " value=\"" + l2Color.ToString() + "\" Des=\"自动计算\"/>"); //Console.WriteLine("<" + keyname + "3" + " value=\"" + l3Color.ToString() + "\" Des=\"自动计算\"/>"); //Console.WriteLine("<" + keyname + "4" + " value=\"" + l4Color.ToString() + "\" Des=\"自动计算\"/>"); //Console.WriteLine("<" + keyname + "5" + " value=\"" + l5Color.ToString() + "\" Des=\"自动计算\"/>"); ElementStylesBase.EnsureResource(keyname + "1" + ".color", l1Color); ElementStylesBase.EnsureResource(keyname + "2" + ".color", l2Color); ElementStylesBase.EnsureResource(keyname + "3" + ".color", l3Color); ElementStylesBase.EnsureResource(keyname + "4" + ".color", l4Color); ElementStylesBase.EnsureResource(keyname + "5" + ".color", l5Color); }
public static HlsColor ConvertRgbToHsl(Color rgbColor) { // Initialize result var hlsColor = new HlsColor(); // Convert RGB values to percentages double r = (double)rgbColor.R / 255; var g = (double)rgbColor.G / 255; var b = (double)rgbColor.B / 255; var a = (double)rgbColor.A / 255; // Find min and max RGB values var min = Math.Min(r, Math.Min(g, b)); var max = Math.Max(r, Math.Max(g, b)); var delta = max - min; /* If max and min are equal, that means we are dealing with * a shade of gray. So we set H and S to zero, and L to either * max or min (it doesn't matter which), and then we exit. */ //Special case: Gray if (max == min) { hlsColor.H = 0; hlsColor.S = 0; hlsColor.L = max; return(hlsColor); } /* If we get to this point, we know we don't have a shade of gray. */ // Set L hlsColor.L = (min + max) / 2; // Set S if (hlsColor.L < 0.5) { hlsColor.S = delta / (max + min); } else { hlsColor.S = delta / (2.0 - max - min); } // Set H if (r == max) { hlsColor.H = (g - b) / delta; } if (g == max) { hlsColor.H = 2.0 + (b - r) / delta; } if (b == max) { hlsColor.H = 4.0 + (r - g) / delta; } hlsColor.H *= 60; if (hlsColor.H < 0) { hlsColor.H += 360; } // Set A hlsColor.A = a; // Set return value return(hlsColor); }