RGB色盘

一直想做一个色盘,用编程的方式生成,无奈技术一直不到位,最后功夫一定不负有心人。

empty  Bitmap bmpcreate = new Bitmap(640, 640);          //创建一张空图 
            pBoxA.Image = bmpcreate;                         //提交给控件,自动形成Image格式数据
            Graphics myGraphicsC = Graphics.FromImage(pBoxA.Image);     //操作指定对象,画在控件图里,pBoxA.Image与curBitmap是两个不同对象
            myGraphicsC.SmoothingMode = SmoothingMode.AntiAlias;
            myPen = new Pen(SelectColor);                  //画线笔的颜色 Color.FromName("black")  System.Drawing.Color.Red
            myGraphicsC.FillRectangle(Brushes.White, pBoxA.ClientRectangle);     //填充pBoxA窗体客户区背景的颜色

            int 中心点x = pBoxA.Width / 2;
            int 中心点y = pBoxA.Height / 2;
            int R = Math.Min(pBoxA.Width, pBoxA.Height);
            myGraphicsC.DrawEllipse(myPen = new Pen(Color.FromArgb(255, 255, 255)), new Rectangle(中心点x - R / 2, 中心点y - R / 2, R, R));//空心圆

            System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(SelectColor);//画刷
            if (pBoxA.Height > pBoxA.Width)
            {
                int r = 255, b = 255, g = 255;
                for (int i = 0; i <= 510; i++)//红色-紫色-蓝色
                {
                    if (i < 255) { r = 255; b = i; } else { r = 510-i; b = 255; }
                    myBrush = new System.Drawing.SolidBrush(Color.FromArgb(r, 0, b));     // 画刷
                    myGraphicsC.FillPie(myBrush, 0, (pBoxA.Height - pBoxA.Width) / 2, R, R, -60 + i * 120 / 510, 85 - i / 6);
                }
                for (int i = 0; i <= 510; i++)//蓝色-青色-绿色 
                {
                    if (i < 255) { b = 255; g = i; } else { b = 510 - i; g = 255; }
                    myBrush = new System.Drawing.SolidBrush(Color.FromArgb(0, g, b));// 画刷
                    myGraphicsC.FillPie(myBrush, 0, (pBoxA.Height - pBoxA.Width) / 2, R, R, 60 + i * 120 / 510, 85 - i / 6);
                }
                for (int i = 0; i <= 510; i++) //绿色-黄色-红色
                {
                    if (i < 255) { g = 255; r = i; } else { g = 510 - i; r = 255; }
                    myBrush = new System.Drawing.SolidBrush(Color.FromArgb(r, g, 0));// 画刷
                    myGraphicsC.FillPie(myBrush, 0, (pBoxA.Height - pBoxA.Width) / 2, R, R, 180 + i * 120 / 510, 85 - i / 6);
                }
            }
            else
            {
                int r = 255, b = 255, g = 255;
                for (int i = 0; i <= 510; i++)//红色-紫色-蓝色
                {
                    if (i < 255) { r = 255; b = i; } else { r = 510 - i; b = 255; }
                    myBrush = new System.Drawing.SolidBrush(Color.FromArgb(r, 0, b));     // 画刷
                    myGraphicsC.FillPie(myBrush, (pBoxA.Width - pBoxA.Height) / 2, 0, R, R, 0+ i * 120 / 510, 85 - i / 6);
                }
                for (int i = 0; i <= 510; i++)//蓝色-青色-绿色 
                {
                    if (i < 255) { b = 255; g = i; } else { b = 510 - i; g = 255; }
                    myBrush = new System.Drawing.SolidBrush(Color.FromArgb(0, g, b));// 画刷
                    myGraphicsC.FillPie(myBrush, (pBoxA.Width - pBoxA.Height) / 2, 0, R, R, 120 + i * 120 / 510, 85 - i / 6);
                }
                for (int i = 0; i <= 510; i++) //绿色-黄色-红色
                {
                    if (i < 255) { g = 255; r = i; } else { g = 510-i; r = 255; }
                    myBrush = new System.Drawing.SolidBrush(Color.FromArgb(r, g, 0));// 画刷
                    myGraphicsC.FillPie(myBrush, (pBoxA.Width - pBoxA.Height) / 2, 0, R, R, 240 + i * 120 / 510, 85 - i / 6);
                }

            }
            pBoxA.Refresh();
            
 


  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值