1

Windows Mobile を使用していますが、画面に線を引いたり、名前を書きたいですか?

GDI+ または関連するものを検索しましたが、実行できませんでした。どうすれば線を引くことができますか? マウスダウンイベントの私のコードは次のとおりですが、滑らかではなく、線のギャップが適切な線の描画ではありません。

int radius = 3; //Set the number of pixel you wan to use here
                //Calculate the numbers based on radius
                int x0 = Math.Max(e.X - (radius / 2), 0),
                    y0 = Math.Max(e.Y - (radius / 2), 0),
                    x1 = Math.Min(e.X + (radius / 2), pbBackground.Width),
                    y1 = Math.Min(e.Y + (radius / 2), pbBackground.Height);
                Bitmap bm = (Bitmap)pbBackground.Image; //Get the bitmap (assuming it is stored that way)
                for (int ix = x0; ix < x1; ix++)
                {
                    for (int iy = y0; iy < y1; iy++)
                    {
                        bm.SetPixel(ix, iy, Color.Black); //Change the pixel color, maybe should be relative to bitmap
                    }
                }
                pbBackground.Refresh();
4

1 に答える 1

2

これを行う最も簡単な方法は、Graphics クラスのインスタンスを使用することです (ただし、探している幅に対して正確に正しい行の配置を取得するために、配置をいじる必要がある場合があります)。

                int radius = 3; //Set the number of pixel you wan to use here
                //Calculate the numbers based on radius
                int x0 = Math.Max(e.X - (radius / 2), 0),
                    y0 = Math.Max(e.Y - (radius / 2), 0),
                    x1 = Math.Min(e.X + (radius / 2), pbBackground.Width),
                    y1 = Math.Min(e.Y + (radius / 2), pbBackground.Height);
                Bitmap bm = (Bitmap)pbBackground.Image; //Get the bitmap (assuming it is stored that way)
                using (Graphics g = Graphics.FromImage(bm))
                {
                    Pen p = new Pen(Color.Black, radius);
                    g.DrawLine(p, x0, y0, x1, y1);
                    p.Dispose();
                }


                pbBackground.Refresh();
于 2012-05-24T17:29:43.783 に答える