Vb.net 在线程中设置picturebox图像
我正在尝试在线程中设置picturebox图像,但我无法设置它Vb.net 在线程中设置picturebox图像,vb.net,multithreading,Vb.net,Multithreading,我正在尝试在线程中设置picturebox图像,但我无法设置它 在特定窗口中拍摄屏幕截图 将picturebox图像设置为屏幕截图 此代码可以在特定窗口中获取屏幕截图,但无法设置picturebox图像。怎么了 Public Function PrintWindow(hwnd As IntPtr) As Bitmap Dim rc As RECT GetWindowRect(hwnd, rc) Dim bmp As New Bitmap(rc.Width, rc.He
- 在特定窗口中拍摄屏幕截图
- 将picturebox图像设置为屏幕截图
Public Function PrintWindow(hwnd As IntPtr) As Bitmap
Dim rc As RECT
GetWindowRect(hwnd, rc)
Dim bmp As New Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb)
Dim gfxBmp As Graphics = Graphics.FromImage(bmp)
Dim hdcBitmap As IntPtr = gfxBmp.GetHdc()
PrintWindow(hwnd, hdcBitmap, 0)
gfxBmp.ReleaseHdc(hdcBitmap)
gfxBmp.Dispose()
Return bmp
End Function
Dim OverviewRefresherThread As New Thread(AddressOf RefreshOverviewThread)
Public Sub RefreshOverviewThread()
Do
MainWindow.PictureBox.Image = PrintWindow(WindowHandle("TEST"))
Loop
End Sub
谢谢…我说得对吗?你想从任何地方得到一个截图,然后把它转移到Picturebox中?如果是这样的话,那么看看这个代码
Dim bounds As Rectangle
Dim screenshot As System.Drawing.Bitmap
Dim graph As Graphics
bounds = Screen.PrimaryScreen.Bounds
screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
PictureBox1.Image = screenshot
此代码获取桌面的屏幕截图,并将其传输到picbox中
你们可以在这里看到教程
如果我没有弄错,你已经完成了屏幕截图,你只需要转移它,这就是你的问题。问题的可能重复之处可能是OP正在尝试从非UI线程更新UI组件。我不知道为什么,我正在试着分析我的答案,看起来否决投票是不合理的。在某些情况下,这段代码会有所帮助,因为它做了用户想要做的事情。啊,忘了它已经坏了。