110,546
社区成员
发帖
与我相关
我的任务
分享
namespace WindowsApplication29
{
public partial class Form1 : Form
{
Point[] Points = new Point[] { new Point(41, 42), new Point(200, 0), new Point(300, 200), new Point(220, 180), new Point(20, 240),
new Point(41,42) };
public Form1()
{
InitializeComponent();
Bitmap bmp = new Bitmap(pictureBox1.Image); // pictureBox1 放的是原图,宽>300,高>220
pictureBox2.Image = bmp; // 拷贝到pictureBox2先
GraphicsUnit gu = GraphicsUnit.Pixel;
RectangleF r = pictureBox2.Image.GetBounds(ref gu);
Region or = new Region(r); // 原始的图片大小的区间
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
gp.AddPolygon(Points);
Region nr = new Region(gp); // 多边形区间
or.Exclude(nr); // 原始的图片大小的区间减去多边形区间后的区间
Graphics g = Graphics.FromImage(pictureBox2.Image);
g.FillRegion(new SolidBrush(Color.Red), or); // 这个区间涂成红色,也就是你说的图片指定多边形区间外的区间
g.Dispose();
}
}
}