更新整理
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using WPFluent.Models;
|
||||
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using WPFluent.Controls;
|
||||
|
||||
|
||||
namespace WPFluent.Extensions
|
||||
{
|
||||
@@ -18,7 +18,7 @@ namespace WPFluent.Extensions
|
||||
/// <param name="hsb"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
public static Color ToColor(this Hsb hsb)
|
||||
public static Color ToColor(this Controls.Hsb hsb)
|
||||
{
|
||||
//0~1
|
||||
var hue = hsb.Hue;
|
||||
@@ -27,15 +27,15 @@ namespace WPFluent.Extensions
|
||||
var opacity = hsb.Opacity;
|
||||
brightness *= 255;
|
||||
//饱和度为0,直接返回亮度值
|
||||
if(saturation.IsCloseTo(0))
|
||||
if (saturation.IsCloseTo(0))
|
||||
return Color.FromArgb((byte)brightness, (byte)brightness, (byte)brightness, (byte)brightness);
|
||||
opacity *= 255;
|
||||
//处理色相超出范围
|
||||
if(hue.IsCloseTo(360))
|
||||
if (hue.IsCloseTo(360))
|
||||
hue = 0;
|
||||
while(hue > 360)
|
||||
while (hue > 360)
|
||||
hue -= 360;
|
||||
while(hue < 0)
|
||||
while (hue < 0)
|
||||
hue += 360;
|
||||
|
||||
//通过色相返回颜色
|
||||
@@ -74,7 +74,7 @@ namespace WPFluent.Extensions
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
public static Hsb ToHsb(this Color color)
|
||||
public static Controls.Hsb ToHsb(this Color color)
|
||||
{
|
||||
double r = color.R;
|
||||
double g = color.G;
|
||||
@@ -95,21 +95,21 @@ namespace WPFluent.Extensions
|
||||
var delta = max - min;
|
||||
var saturation = max.IsCloseTo(0) ? 0 : delta / max;
|
||||
|
||||
if(max.IsCloseTo(min))
|
||||
if (max.IsCloseTo(min))
|
||||
{
|
||||
hue = 0; // 无色,未定义
|
||||
}
|
||||
else
|
||||
{
|
||||
if(max.IsCloseTo(r))
|
||||
if (max.IsCloseTo(r))
|
||||
{
|
||||
hue = (g - b) / delta + (g < b ? 6 : 0);
|
||||
}
|
||||
else if(max.IsCloseTo(g))
|
||||
else if (max.IsCloseTo(g))
|
||||
{
|
||||
hue = (b - r) / delta + 2;
|
||||
}
|
||||
else if(max.IsCloseTo(b))
|
||||
else if (max.IsCloseTo(b))
|
||||
{
|
||||
hue = (r - g) / delta + 4;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user