私は、マウスをクリックしたり移動したりしてピクセルの色を塗りつぶすなどの基本的なペイント機能を可能にするピクセル "グリッド"を作成する最善の方法を見つけようとしています。テキストや図形をピクセルにレンダリングするために、コピー、貼り付け、移動、または他のグラフィック機能を使用するための領域。私はthis exampleのようないくつかのサンプルを見てきましたが、これはパネルコントロールを無効にして、私が達成しようとしているものと似たようなものですが、ペイントが遅く、マウス。私が探している機能を可能にするコントロール、あるいは私が上書きできるコントロールはありますか?ペイントピクセルとレンダリングテキストのグリッドを作成する
ここで、上記の例は、どのように見えるかのサンプルです: Sample pixel grid
そして、私は上記の例から適応コード:
public class Pixel
{
public Rectangle Bounds { get; set; }
public bool IsOn { get; set; }
public bool IsSelected { get; set; }
}
public class PixelGridControl : Panel
{
public int Columns = 99;
public int Rows = 63;
private readonly Pixel[,] pixels;
public PixelGridControl()
{
this.DoubleBuffered = true;
this.ResizeRedraw = true;
// initialize pixel grid:
pixels = new Pixel[Columns, Rows];
for (int y = 0; y < Rows; ++y)
{
for (int x = 0; x < Columns; ++x)
{
pixels[x, y] = new Pixel();
}
}
}
// adjust each column and row to fit entire client area:
protected override void OnResize(EventArgs e)
{
int top = 0;
for (int y = 0; y < Rows; ++y)
{
int left = 0;
int height = (this.ClientSize.Height - top)/(Rows - y);
for (int x = 0; x < Columns; ++x)
{
int width = (this.ClientSize.Width - left)/(Columns - x);
pixels[x, y].Bounds = new Rectangle(left, top, width, height);
left += width;
}
top += height;
}
base.OnResize(e);
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
for (int y = 0; y < Rows; ++y)
{
for (int x = 0; x < Columns; ++x)
{
if (pixels[x, y].IsOn)
{
e.Graphics.FillRectangle(Brushes.Gold, pixels[x, y].Bounds);
}
else
{
ControlPaint.DrawButton(e.Graphics, pixels[x, y].Bounds,
ButtonState.Normal);
}
}
}
base.OnPaint(e);
}
// determine which button the user pressed:
protected override void OnMouseDown(MouseEventArgs e)
{
for (int y = 0; y < Rows; ++y)
{
for (int x = 0; x < Columns; ++x)
{
if (pixels[x, y].Bounds.Contains(e.Location))
{
pixels[x, y].IsOn = true;
this.Invalidate();
MessageBox.Show(
string.Format("You pressed on button ({0}, {1})",
x.ToString(), y.ToString())
);
}
}
}
base.OnMouseDown(e);
}
}
なぜGDI +が遅いですか?そして、あなたは[Double Buffered Graphics](https://msdn.microsoft.com/en-us/library/b367a457(v=vs.110).aspx)を知っていましたか? –
私はGDI +が遅いと言っているのではなく、私がリンクしている例で言及していた実装だけです。私はその記事を編集し、あなたが参照しているDoubleBufferedグラフィックスを利用してテストしているコードを追加しました。マウスボタンをクリックすると実際の矩形領域の色が変わるまでに約2秒かかります。私は、異なるコントロールがあるか、これを実装する別の方法があるかどうかを知ろうとしています。これは遅れずに流体体験を提供します。 – Rob
デモテストプロジェクトを** github **に委託して他の人たちがテストできるか? –