| | |
| | | //{ |
| | | var color = rgbString.Split(","); |
| | | //} |
| | | if(color.Length!= 3) |
| | | if(color.Length < 3) |
| | | { |
| | | color = new string[] {"255", "255", "255" }; |
| | | } |
| | |
| | | |
| | | #endregion |
| | | |
| | | #region RGBW |
| | | /// <summary> |
| | | /// 获取rgbw颜色 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public int GetRGBWcolor(string rgbwString) |
| | | { |
| | | var color = rgbwString.Split(","); |
| | | //} |
| | | if (color.Length != 4) |
| | | { |
| | | color = new string[] { "255", "255", "255" }; |
| | | } |
| | | 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> |
| | | /// <param name="function"></param> |
| | | /// <returns></returns> |
| | | public byte[] GetRGBWbytes(Function function) |
| | | { |
| | | var color = function.GetAttrState(FunctionAttributeKey.RGBW).Split(","); |
| | | |
| | | if (color.Length != 4) |
| | | { |
| | | color = new string[] { "100", "100", "100","100" }; |
| | | } |
| | | byte redColor = 0; |
| | | byte greenColor = 0; |
| | | byte blueColor = 0; |
| | | byte wColor = 0; |
| | | |
| | | byte.TryParse(color[0], out redColor); |
| | | byte.TryParse(color[1], out greenColor); |
| | | byte.TryParse(color[2], out blueColor); |
| | | byte.TryParse(color[3], out wColor); |
| | | |
| | | return new byte[] { redColor, greenColor, blueColor,wColor }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取rgbw 控制字符串 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public string GetRGBWcolorString(Function function) |
| | | { |
| | | var color = function.GetAttrState(FunctionAttributeKey.RGBW).Split(","); |
| | | return color[0] + "," + color[1] + "," + color[2] + "," + color[3]; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取rgbW颜色 |
| | | /// </summary> |
| | | /// <param name="index">0:red 1:green 2:blue</param> |
| | | /// <returns></returns> |
| | | public int GetRGBWColor(int index, Function function) |
| | | { |
| | | int color = 0; |
| | | if (index <= 2) |
| | | { |
| | | try |
| | | { |
| | | int.TryParse(function.GetAttrState(FunctionAttributeKey.RGBW).Split(",")[index], out color); |
| | | } |
| | | catch { } |
| | | } |
| | | return color; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置rgbw颜色 |
| | | /// </summary> |
| | | public void SetRGBWcolor(byte[] color, Function function) |
| | | { |
| | | |
| | | function.SetAttrState(FunctionAttributeKey.RGBW, color[0] + "," + color[1] + "," + color[2] + "," + color[3]); |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | } |
| | | } |