2

ビットマップ オブジェクト (またはその他の画像) があり、このビットマップに線を引いて多角形を作成しています。描画後、(線に基づいて) 選択領域を複製/コピー/カットする必要があります。

bitmap.clone メソッドは四角形でのみ機能するため、使用できません。

Point[] または GraphicsPath に基づくある種のクローン実装が必要です...

GDI/グラフィックスの初心者を助けてください... :)

アップデート

私はこのようなことをしてみました:

Graphics g = pbImage.CreateGraphics();
g.Clip = new Region(path);
Image img = null;
g.DrawImage(img, new Point(0, 0));

コード例を提供できますか? 私は GDI+ が初めてで、あなたが提案したことを実装できません。

私は理解していません:

別のバッファ/一時グラフィックス オブジェクト

4

2 に答える 2

4

Barndon Moretzs ソリューションの例。

        int x = 0;
        int y = 0;
        int width = 0;
        int height = 0;

        Point[] pesource = null;
        GraphicsPath gpdest = new GraphicsPath();

        source = new Bitmap(Image.FromFile(@"IMAGEPATH"));

        //Your polygon
        pesource = new Point[]
        {
            new Point(10,100),
            new Point(30,150),
            new Point(40,170),
            new Point(60,120),
            new Point(70,250),
            new Point(40,300),
            new Point(10,250),
            new Point(30,150)
        };

        //Determine the destination size/position
        x = source.Width;
        y = source.Height;

        foreach (var p in pesource)
        {
            if (p.X < x)
                x = p.X;
            if (p.X > width)
                width = p.X;

            if (p.Y < y)
                y = p.Y;
            if (p.Y > height)
                height = p.Y;
        }

        height = height - y;
        width = width - x;



        gpdest.AddPolygon(pesource);
        Matrix m = new Matrix(1, 0, 0, 1, -x, -y);
        gpdest.Transform(m);

        //Create the Bitmap
        clipped = new Bitmap(width, height);

        //Draw on the Bitmap
        using (Graphics g = Graphics.FromImage(clipped))
        {
            GraphicsPath gpgdi = new GraphicsPath();
            g.SetClip(gpdest);
            g.DrawImage(source, -x, -y);
        }
于 2011-08-08T08:33:55.397 に答える
2

Graphics.Clipを使用して、「ソース」ビットマップ/イメージから作成されたカスタム クリッピング領域 ( GraphicsPath から) を指定し、それを別のバッファ/一時グラフィック オブジェクトに再描画して、目的の結果を得ることができます。

これは最も効率的な解決策ではありませんが、少なくとも正しい方向に進むはずです。

于 2011-08-07T17:50:59.547 に答える