使用gdi+实时绘制picturebox(画个叉)
作者:互联网
private void DrawReticle(System.Drawing.Point pt, int size)//画一个透明的前景图片上画十字
{
Bitmap bmp = new Bitmap(imageWindows[2].Width, imageWindows[2].Height);//用图片大小不要用控件大小
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.Transparent);
Pen MyPen = new Pen(Color.Red, 1);
System.Drawing.Point pt1 = new System.Drawing.Point(pt.X - size, pt.Y);
System.Drawing.Point pt2 = new System.Drawing.Point(pt.X + size, pt.Y);
System.Drawing.Point pt3 = new System.Drawing.Point(pt.X, pt.Y - size);
System.Drawing.Point pt4 = new System.Drawing.Point(pt.X, pt.Y + size);
//使用DrawLine方法绘制直线
g.DrawLine(MyPen, pt1, pt2);
g.DrawLine(MyPen, pt3, pt4);
g.Dispose();
imageWindows[2].Image = bmp;
}
private void RealTimeGrab()
{
while (true)
{
if (isOpen)
{
System.Drawing.Point pt1 = new System.Drawing.Point(int.Parse(nudXCoord.Text), int.Parse(nudYCoord.Text));
DrawReticle(pt1, int.Parse(nudReticleSize.Text));
}
imageWindows[2].BeginInvoke(new Action(() =>
{
imageWindows[2].BackgroundImage = dst;//给背景图赋值 Bitmap dst
}));
}
}
标签:pt,Point,System,new,picturebox,gdi,画个,Drawing,size 来源: https://www.cnblogs.com/dengzhekaihua/p/15712322.html