使用Image LockBits绘制位图

时间:2013-05-03 11:12:25

标签: .net aforge

我每秒有20帧。而且我在每一帧上画了一些线条,我得到的线条没有问题,但背景图像常常卡住。随机我得到10帧相同的图像,但线看起来很好。

if (cizik == null)
{
BitmapData imageData = CloneOrj2.LockBits(new Rectangle(0, 0, CloneOrj2.Width, CloneOrj2.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
UnmanagedImage tmp = new UnmanagedImage(imageData);
cizik = UnmanagedImage.Create(CloneOrj2.Width, CloneOrj2.Height, PixelFormat.Format24bppRgb);
tmp.Copy(cizik);
Drawing.Line(cizik, new IntPoint(XX, XX), new IntPoint(XX, XX), System.Drawing.Color.Yellow);
}
else
{ 
BitmapData imageData = CloneOrj2.LockBits(new Rectangle(0, 0, CloneOrj2.Width, CloneOrj2.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
UnmanagedImage tmp = new UnmanagedImage(imageData);
Drawing.Line(tmp, new IntPoint(XX, XX), new IntPoint(XX, XX), System.Drawing.Color.Yellow);
cizik = UnmanagedImage.Create(CloneOrj2.Width, CloneOrj2.Height, PixelFormat.Format24bppRgb);
tmp.Copy(cizik);
}

DrawScreenActual.Image = (System.Drawing.Image)cizik.ToManagedImage().Clone();

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

也许你的代码没有完全显示,但是在LockBits之后你必须解锁这些位。

为此,必须在位图对象中使用UnlockBits方法。我会在DrawLine之后调用它。

也许有问题!