/// <summary> /// 根据渐变选择器在渐变画布中的位置改变颜色 /// </summary> /// <param name="p">渐变选择器的中心相对于渐变画布的坐标</param> protected void UpdateColorFromPoint(Point p) { if (p.X < 0) { p.X = 0; } if (p.X > shadeCanvas.ActualWidth) { p.X = shadeCanvas.ActualWidth; } if (p.Y < 0) { p.Y = 0; } if (p.Y > shadeCanvas.ActualHeight) { p.Y = shadeCanvas.ActualHeight; } //计算新的颜色 HsvColor hsvColor = lastPreciseColor.HasValue ? lastPreciseColor.Value : HsvColor.FromArgb(spectrumSlider.SelectedColor); if (!lastPreciseColor.HasValue) { hsvColor.A = (double)Color.A / 255; } hsvColor.S = p.X / shadeCanvas.ActualWidth; hsvColor.V = 1 - p.Y / shadeCanvas.ActualHeight; //更新颜色 UpdateColor(hsvColor.ToArgb(), hsvColor); }
/// <summary> /// 频谱选择器的选择改变时触发 /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedPropertyChangedEventArgs<System.Double>"/> instance containing the event data.</param> void spectrumSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { //频谱选择已改变,需更新颜色 HsvColor hsvColor = lastPreciseColor.HasValue ? lastPreciseColor.Value : HsvColor.FromArgb(Color); hsvColor.H = spectrumSlider.Value; UpdateColor(hsvColor.ToArgb(), hsvColor); }