wei
2021-04-14 1498a62d1d44d715e310b42e3133aa8cdc6eec92
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
 
namespace HDL_ON.Entity
{
    public class Light 
    {
        #region RGB
        /// <summary>
        /// 获取rgb颜色
        /// </summary>
        /// <returns></returns>
        public int GetRGBcolor(Function function )
        {
            var color = function.GetAttrState(FunctionAttributeKey.RGB).Split(",");
 
            if(color.Length!= 3)
            {
                color = new string[] {"100", "100", "100" };
            }
            int redColor = 0;
            int greenColor = 0;
            int blueColor = 0;
 
            int.TryParse(color[0], out redColor);
            int.TryParse(color[1], out greenColor);
            int.TryParse(color[2], out blueColor);
 
            int recolor = redColor * 256 * 256 + greenColor * 256 + blueColor;
 
            return recolor;
        }
        /// <summary>
        /// 获取rgb 控制字符串
        /// </summary>
        /// <returns></returns>
        public string GetRGBcolorString(Function function )
        {
            var color = function.GetAttrState(FunctionAttributeKey.RGB).Split(",");
            return color[0] + "," + color[1] + "," + color[2];
        }
 
        /// <summary>
        /// 获取rgb颜色
        /// </summary>
        /// <param name="index">0:red 1:green 2:blue</param>
        /// <returns></returns>
        public int GetColor( int index,Function function)
        {
            int color = 0;
            if (index <= 2)
            {
                try
                {
                    int.TryParse(function.GetAttrState(FunctionAttributeKey.RGB).Split(",")[index], out color);
                }
                catch { }
            }
            return color;
        }
 
        /// <summary>
        /// 设置rgb颜色
        /// </summary>
        public void SetRGBcolor(byte[] color,Function function)
        {
            function.SetAttrState(FunctionAttributeKey.RGB, color[0] + "," + color[1] + "," + color[2]);
        }
 
        #endregion
 
    }
}