カスタムカラーダイアログを作成しています。赤い四角形の注記のようになります 。下の虹の mouse_move イベントでこの色相スライドを描画します。私の問題は描画速度です。少し遅いです。このパネルを描画する別の方法はありますか? これが私のコードです:
// picColorRuler is the rainbow below
// picColorArea is the panel with red border in the attached image
// Change the target location.
private void picColorRuler_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
rulerColorTarget.Left = e.X;
if (rulerColorTarget.Left < 0) rulerColorTarget.Left = 0;
if (rulerColorTarget.Left > picColorRuler.ClientSize.Width - 1)
{
rulerColorTarget.Left = picColorRuler.ClientSize.Width - 1;
}
picColorRuler.Refresh();
}
}
// Painting the rainbow.
private void picColorRuler_Paint(object sender, PaintEventArgs e)
{
// Draw the target.
rulerColorTarget.Color = rulerImg.GetPixel(rulerColorTarget.Left, rulerColorTarget.Top);
rulerColorTarget.Draw(e.Graphics);
// Change the picColorArea's colors.
PaintPicColorArea();
}
private void PaintPicColorArea()
{
var width = picColorArea.ClientSize.Width;
var height = picColorArea.ClientSize.Height;
var satSeed = 1f / width;
var lightSeed = 1f / height;
var sat = 0f;
for (var x = 0; x < width; ++x)
{
if (x == width - 1) sat = 1;
var light = 0f;
for (var y = 0; y < height; ++y)
{
if (y == height - 1) light = 1;
var sc = Util.Hsl2Rgb(rulerColorTarget.Color.GetHue(), sat, light);
areaImg.SetPixel(x, y, sc);
light += lightSeed;
}
sat += satSeed;
}
picColorArea.BackgroundImage = null;
picColorArea.BackgroundImage = areaImg;
}