/// <summary> /// 色相の取得 /// </summary> /// <param name="grp"></param> /// <param name="pict"></param> /// <param name="param"></param> private void GetHue(GroupBox grp, PictureBox pict, ref Color.Param param) { int ix = Cursor.Position.X - (Location.X + grp.Location.X + pict.Location.X + 9); int iy = Cursor.Position.Y - (Location.Y + grp.Location.Y + pict.Location.Y + 31); double px = 2.0 * ix / pict.Width - 1.0; double py = 1.0 - 2.0 * iy / pict.Height; param.H = (int)(45 * Math.Atan2(py, px) / Math.Atan(1.0) + 0.5); }
/// <summary> /// HSL色空間の描画 /// </summary> /// <param name="pictH"></param> /// <param name="pictS"></param> /// <param name="pictL"></param> /// <param name="param"></param> private void DrawHSL(PictureBox pictH, PictureBox pictS, PictureBox pictL, Color.Param param) { Pen penNorm = new Pen(System.Drawing.Color.Black, 1.0f); Pen penBold = new Pen(System.Drawing.Color.Black, 4.0f); Color.HSL hsl = new Color.HSL(); //*** 色相環の描画 ***// Bitmap bmpHue = new Bitmap(BmpHue.Width, BmpHue.Height); Graphics gHue = Graphics.FromImage(bmpHue); RectangleF rectHue = new RectangleF(0.0f, 0.0f, bmpHue.Width, bmpHue.Height); double th = -Math.Atan(1.0) * param.H / 45.0; float ax = (float)(bmpHue.Width * Math.Cos(th) / 2.0); float ay = (float)(bmpHue.Height * Math.Sin(th) / 2.0); float bx = 0.75f * ax + bmpHue.Width / 2.0f; float by = 0.75f * ay + bmpHue.Height / 2.0f; ax += bmpHue.Width / 2.0f; ay += bmpHue.Height / 2.0f; gHue.DrawImage(BmpHue, 0, 0); gHue.DrawArc(penBold, rectHue, -param.H, param.HWidth); gHue.DrawArc(penBold, rectHue, -param.H - param.HWidth, param.HWidth); gHue.DrawLine(penNorm, new PointF(ax, ay), new PointF(bx, by)); pictH.Image = bmpHue; //*** 彩度と明度の描画 ***// Bitmap bmpS = new Bitmap(pictS.Width, pictS.Height); Bitmap bmpL = new Bitmap(pictL.Width, pictL.Height); byte[] pixS = new byte[bmpS.Width * bmpS.Height * 4]; byte[] pixL = new byte[bmpL.Width * bmpL.Height * 4]; BitmapData bmpSData = bmpS.LockBits( new Rectangle(0, 0, bmpS.Width, bmpS.Height) , ImageLockMode.ReadOnly , bmpS.PixelFormat ); BitmapData bmpLData = bmpL.LockBits( new Rectangle(0, 0, bmpL.Width, bmpL.Height) , ImageLockMode.ReadOnly , bmpL.PixelFormat ); double k = 100.0 / bmpS.Width; for (int px = 0, s = 0; px < bmpS.Width; ++px, s += 4) { hsl.H = param.H; hsl.S = (int)(k * px); hsl.L = 50; hsl.A = 255; Color.HSLtoRGB(ref hsl, ref pixS, ref s); hsl.H = param.H; hsl.S = param.SMax; hsl.L = (int)(k * px); hsl.A = 255; Color.HSLtoRGB(ref hsl, ref pixL, ref s); } for (int py = 0, s = 0; py < bmpS.Height; ++py, s += bmpSData.Stride) { Array.Copy(pixS, 0, pixS, s, bmpSData.Stride); Array.Copy(pixL, 0, pixL, s, bmpSData.Stride); } Marshal.Copy(pixS, 0, bmpSData.Scan0, pixS.Length); Marshal.Copy(pixL, 0, bmpLData.Scan0, pixL.Length); bmpS.UnlockBits(bmpSData); bmpL.UnlockBits(bmpLData); pictS.Image = bmpS; pictL.Image = bmpL; }