跨线程图片盒pointtoscreen [英] cross thread picturebox pointtoscreen

查看:88
本文介绍了跨线程图片盒pointtoscreen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Using bitmap As New Bitmap(CameraView.Width, CameraView.Height)
      Using g As Graphics = Graphics.FromImage(bitmap)
           ' Get the paramters to call g.CopyFromScreen and get the image
           Dim rectanglePanelVideoPreview As Rectangle = CameraView.Bounds
           Dim sourcePoints As System.Drawing.Point = CameraView.PointToScreen(New System.Drawing.Point(CameraView.ClientRectangle.X, CameraView.ClientRectangle.Y))
            g.CopyFromScreen(sourcePoints, System.Drawing.Point.Empty, rectanglePanelVideoPreview.Size)
       End Using
End Using



i希望使用backgroundworker来执行该代码,但因使用PointToScreen而出现错误。

请帮我重新编写跨线程代码。 Thx


i want to use backgroundworker to do that code, but got error because use PointToScreen.
Please help me re-code with cross-thread. Thx

推荐答案

实际绘图必须在UIThread中完成。这是运行应用程序和处理用户界面的主线程。您需要告诉UI线程调用该方法,以便允许它进行屏幕更新。在后台工作者中,您只能在实际绘图之前完成所有工作。完成工作后,您将调用更新UI的方法。该方法应检查是否需要调用,这意味着另一个线程正在调用该方法,它将自动调用自己在UI线程上执行。



Actual drawing must be done in the UIThread. This is the main thread running the application and handling the user interface. You need to tell the UI Thread to invoke the method so it is allowed to do screen updates. In the backgroundworker you would only do all the work prior to the actual drawing. When the work is done you then invoke a method that updates the UI. That method should check if an invoke is required, meaning that is another thread is calling the method, it will automatically invoke itself to be executed on the UI thread.

If Me.InvokeRequired Then
    Me.Invoke(New MethodInvoker(AddressOf AccessControl))
Else





查看此链接了解更多信息:

http://msdn.microsoft.com/en -us / library / ms171728%28v = vs.85%29.aspx?cs-save-lang = 1& cs-lang = vb#code-snippet-1 [ ^ ]



祝你好运!



Check this link for more info:
http://msdn.microsoft.com/en-us/library/ms171728%28v=vs.85%29.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1[^]

Good luck!


这篇关于跨线程图片盒pointtoscreen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆