• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#高仿腾讯QQ(QQ皮肤颜色滑动调色器)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

       《QQ皮肤颜色滑动调色器》这个控件去年时就发到群共享了,但一直没发到博客上去。主要呢就是一个是没时间去写博客,还有就是程序有很多BUG还没完善,比如拖动下面滑动条时不是十分的顺畅,占用CPU资源也很等,但在这里还是发出来,大家自己去改善吧!


 

       这个控件刚开始做时原本是打算通过截取一张QQ滑动调色器的图片做为控件调色板背景颜色的,但后来,无意间在网上看到一个老外写的基于HSL色调(H)的调色板程序,而QQ滑动调色器改变颜色的方法是基于(HSL)饱和度(S)(HSL:HSL色彩模式是工业界的一种颜色标准,是通过对色调(H)、饱和度(S)、亮度(L)三个颜色通道的变化以及它们相互之间的叠加来得到各式各样的颜色的,HSL即是代表色调,饱和度,亮度三个通道的颜色,而饱和度(S)懂PS的人应该很清楚,我也是直接截个图放到PS里,再改变他的饱和度才知道QQ是基于饱和度)来变换颜色的,所以我变偿试着改了改他的程序,让他基于饱和度的调节而变换颜色达到QQ的效果。

      这是在PS里的颜色变换图:


       控件最主要就是RGB与HSL颜色通道之间的换算,至于算法、原理,我想大家去问问百度大叔、Google大妈理解会来得更容易些,在这里我就不说了,让我说我也说不好,呵呵。

       颜色控件由另两个控件组成,一个是 颜色显示区,我单独做成了一个控件。另一个是滑动模块,也是单独做成了一个控件
    
       还是直接贴源,有兴趣的大家自己研究:

ColorAreaAndSliderUserControl.cs完整控件

 

1 //作者:阿龙(Along)
2  //QQ号:646494711
3  //QQ群1:57218890
4  //QQ群2:57219423
5  //网站:http://www.8timer.com
6  //博客:http://www.cnblogs.com/Along729/
7  //声明:未经作者许可,任何人不得发布出售该源码,请尊重别人的劳动成果,谢谢大家支持
8  using System;
9  using System.Collections.Generic;
10  using System.ComponentModel;
11  using System.Drawing;
12  using System.Data;
13  using System.Linq;
14  using System.Text;
15  using System.Windows.Forms;
16  using ColorCustomize.Colors;
17
18  namespace ColorCustomize
19 {
20 public partial class ColorAreaAndSliderUserControl : UserControl
21 {
22 double h, l, s;
23 public ColorAreaAndSliderUserControl()
24 {
25 InitializeComponent();
26 }
27
28 private void colorAreaUserControl1_HueSaturationChanged(object sender, EventArgs e)
29 {
30
31 colorAreaUserControl.GetHueSaturation(out h,out s, out l);
32 colorSliderUserControl.SetHueSaturation(h, s, l);
33
34 }
35
36 private void colorAreaUserControl1_ValueChangedByUser(object sender, EventArgs e)
37 {
38 notifyColorChanged();
39 notifyValueChangedByUser();
40 }
41
42 private void colorSliderUserControl_ValueChanged(object sender, EventArgs e)
43 {
44 double s;
45 colorSliderUserControl.GetHueSaturation(out s);
46 colorAreaUserControl.SetHueSaturation(s);
47
48 }
49
50 private void colorSliderUserControl_ValueChangedByUser(object sender, EventArgs e)
51 {
52 notifyColorChanged();
53 notifyValueChangedByUser();
54
55 }
56
57 /// <summary>
58 /// 当用户发生改变颜色.
59 /// </summary>
60   public event EventHandler ColorChanged;
61
62 /// <summary>
63 /// 值时发生了改变.
64 /// </summary>
65 public event EventHandler ValueChangedByUser;
66
67 private void notifyColorChanged()
68 {
69 if (ColorChanged != null)
70 {
71 ColorChanged(this, EventArgs.Empty);
72 }
73 }
74
75 private void notifyValueChangedByUser()
76 {
77 if (ValueChangedByUser != null)
78 {
79 ValueChangedByUser(this, EventArgs.Empty);
80 }
81 }
82
83 public void setColor(Color color)
84 {
85 RgbColor rgb = ColorConverting.ColorToRgb(color);
86 HslColor hsl = ColorConverting.RgbToHsl(rgb);
87 colorAreaUserControl.SetColor((double)hsl.Hue,(double)hsl.Saturation,(double)hsl.Light);
88 colorSliderUserControl.SetColorSaturation((double)hsl.Saturation);
89 }
90 public void GetColor(out Color color)
91 {
92 color = ColorConverting.HslToRgb(new HslColor(h,s,l)).ToColor();
93 }
94 }
95 }

ColorAreaUserControl.cs颜色显示区控件

1 //作者:阿龙(Along)
2 //QQ号:646494711
3 //QQ群1:57218890
4 //QQ群2:57219423
5 //网站:http://www.8timer.com
6 //博客:http://www.cnblogs.com/Along729/
7 //声明:未经作者许可,任何人不得发布出售该源码,请尊重别人的劳动成果,谢谢大家支持
8 using System;
9 using System.Collections.Generic;
10 using System.ComponentModel;
11 using System.Drawing;
12 using System.Drawing.Drawing2D;
13 using System.Data;
14 using System.Linq;
15 using System.Text;
16 using System.Windows.Forms;
17 using ColorCustomize.Colors;
18 using System.Threading;
19
20 namespace ColorCustomize
21 {
22 public partial class ColorAreaUserControl : UserControl
23 {
24 private double _h;
25 private double _l;
26 private static double _s=100;
27 private Bitmap _colorBitmap;
28
29 public ColorAreaUserControl()
30 {
31 InitializeComponent();
32 SetStyle(ControlStyles.UserPaint |
33 ControlStyles.DoubleBuffer |
34 ControlStyles.ResizeRedraw|
35 ControlStyles.Selectable |
36 ControlStyles.AllPaintingInWmPaint,
37 true);
38 }
39
40 //public void SetHueSaturation(double h, double l)
41 //{
42 // _h = h;
43 // _l = l;
44 // Invalidate();
45
46 // // notifyHueSaturationChanged();
47 //}
48
49
50 public void SetHueSaturation(double s)
51 {
52 _s = s;
53 Calculate();
54 //ThreadStart threadStart = new ThreadStart(Calculate);
55 //Thread thread = new Thread(threadStart);
56 //thread.Start();
57
58 drawCaret();
59 notifyHueSaturationChanged();
60 }
61 public void Calculate()
62 {
63 _colorBitmap = drawColorBitmap();
64 }
65
66
67
68 public void SetColor(double h,double s,double l)
69 {
70 _h = h;
71 _l = l;
72 _s = s;
73 _colorBitmap = drawColorBitmap();
74 drawCaret();
75 // notifyValueChangedByUser();
76 notifyHueSaturationChanged(); ;
77 }
78
79 public void GetHueSaturation(out double h,out double s, out double l)
80 {
81 h = _h;
82 l = _l;
83 s = _s;
84 }
85
86
87 /// <summary>
88 /// Occurs when the user changed the hue and/or saturation.
89 /// 当用户发生改变色调和/或饱和度
90 /// </summary>
91 public event EventHandler HueSaturationChanged;
92
93 /// <summary>
94 /// Occurs when a value has been changed.
95 /// 值更改时发生事件
96 /// </summary>
97 public event EventHandler ValueChangedByUser;
98
99 private void notifyHueSaturationChanged()
100 {
101 if (HueSaturationChanged != null)
102 {
103 HueSaturationChanged(this, EventArgs.Empty);
104 }
105 }
106
107 private void notifyValueChangedByUser()
108 {
109 if (ValueChangedByUser != null)
110 {
111 ValueChangedByUser(this, EventArgs.Empty);
112 }
113 }
114
115 /// <summary>
116 /// 重绘控件
117 /// </summary>
118 /// <param name="e"></param>
119 protected override void OnPaint(PaintEventArgs e)
120 {
121 base.OnPaint(e);
122 if (_colorBitmap == null)
123 {
124 _colorBitmap = drawColorBitmap();
125 }
126 double facXBmpToScreen = (double)_colorBitmap.Width / ClientSize.Width;
127 double facYBmpToScreen = (double)_colorBitmap.Height / ClientSize.Height;
128
129 var sourceRect = new Rectangle(
130 (int)(facXBmpToScreen * ClientRectangle.Left),
131 (int)(facYBmpToScreen * ClientRectangle.Top),
132 (int)(facXBmpToScreen * ClientRectangle.Width),
133 (int)(facYBmpToScreen * ClientRectangle.Height));
134 //e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
135 e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
136 e.Graphics.DrawImage(
137 _colorBitmap,
138 ClientRectangle,
139 sourceRect,
140 GraphicsUnit.Pixel);
141 drawCaret(e.Graphics);
142 }
143
144 /// <summary>
145 /// 绘制位图的颜色
146 /// </summary>
147 /// <returns></returns>
148 private static Bitmap drawColorBitmap()
149 {
150 const int width = 360;
151 const int height = 100;
152
153 var bmp = new Bitmap(width, height);
154
155 for (int y = 0; y < height; ++y)
156 {
157 for (int x = 0; x < width; ++x)
158 {
159 double h = x;
160 double s = _s;//饱和度
161 double l = 100 - y;
162
163 Color color = new HslColor(h, s, l).ToColor();
164
165 bmp.SetPixel(x, y, color);
166 }
167 }
168
169 return bmp;
170 }
171
172 /// <summary>
173 /// 绘制移动圆点
174 /// </summary>
175 /// <param name="g">The g.</param>
176 private

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c#进阶之神奇的CSharp发布时间:2022-07-10
下一篇:
c#调用打印机发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap