在线程中设置picturebox图像

时间:2016-12-07 20:05:08

标签: vb.net multithreading

我正在尝试在线程中设置图片框图像,但我无法设置它

  • 在特定窗口中截取屏幕截图
  • 将图片框图片设为截图

此代码可以在特定窗口中截图,但无法将图片框图像设置为它。怎么了?

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

感谢...

1 个答案:

答案 0 :(得分:-1)

我是对的吗?你想要从Whatever获取屏幕截图并在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中。

你可以在这里看到教程。

http://vb6.wonderhowto.com/how-to/capture-desktop-screen-with-vb-net-0158485/

如果我没弄错,你已经完成了屏幕截图,你只需要转移它,这就是你的问题。