ColorRGB.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Text;
  5. namespace TEAMModelOS.Test.PPTX.ColorLibrary
  6. {
  7. /// <summary>
  8. /// 类 名:ColorRGB
  9. /// 功 能:R 红色 \ G 绿色 \ B 蓝色 颜色模型
  10. /// 所有颜色模型的基类,RGB是用于输出到屏幕的颜色模式,所以所有模型都将转换成RGB输出
  11. /// </summary>
  12. public class ColorRGB
  13. {
  14. /// <summary>
  15. /// 构造方法
  16. /// </summary>
  17. /// <param name="r"></param>
  18. /// <param name="g"></param>
  19. /// <param name="b"></param>
  20. public ColorRGB(int r, int g, int b)
  21. {
  22. this._r = r;
  23. this._g = g;
  24. this._b = b;
  25. }
  26. private int _r;
  27. private int _g;
  28. private int _b;
  29. /// <summary>
  30. /// 红色
  31. /// </summary>
  32. public int R
  33. {
  34. get { return this._r; }
  35. set
  36. {
  37. this._r = value;
  38. this._r = this._r > 255 ? 255 : this._r;
  39. this._r = this._r < 0 ? 0 : this._r;
  40. }
  41. }
  42. /// <summary>
  43. /// 绿色
  44. /// </summary>
  45. public int G
  46. {
  47. get { return this._g; }
  48. set
  49. {
  50. this._g = value;
  51. this._g = this._g > 255 ? 255 : this._g;
  52. this._g = this._g < 0 ? 0 : this._g;
  53. }
  54. }
  55. /// <summary>
  56. /// 蓝色
  57. /// </summary>
  58. public int B
  59. {
  60. get { return this._b; }
  61. set
  62. {
  63. this._b = value;
  64. this._b = this._b > 255 ? 255 : this._b;
  65. this._b = this._b < 0 ? 0 : this._b;
  66. }
  67. }
  68. /// <summary>
  69. /// 获取实际颜色
  70. /// </summary>
  71. /// <returns></returns>
  72. public Color GetColor()
  73. {
  74. return Color.FromArgb(this._r, this._g, this._b);
  75. }
  76. }
  77. }