一直想做一个色盘,用编程的方式生成,无奈技术一直不到位,最后功夫一定不负有心人。
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();