Results 1 to 40 of 102

Thread: Problems getting a window capture with Bitblt and PrintWindow.

Threaded View

  1. #11
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,650

    Cool Re: Problems getting a window capture with Bitblt and PrintWindow.

    Feel free to contribute with your code about image recognition.

    If we are talking strictly about taking screenshots of videos then you could always do that with a simple "BitBlt" from the desktop window. This "WinRT Capture" approach has two main advantages over that:

    1. It works while the video is playing in the background as long as its window is not minimized.
    2. You can capture multiple frames at a time (I think the number of frames is capped at the refresh rate of your monitor, for example 60 frames per second).

    You can modify the number of frames in the following line of code. Where it currently says "1", you can put any number of frames:

    Code:
    Invoke(pIDirect3D11CaptureFramePoolStatics, IDirect3D11CaptureFramePoolStatics_Create, ObjPtr(objIDirect3DDevice), _
    DXGI_FORMAT_B8G8R8A8_UNORM, 1, m_lWidth, m_lHeight, VarPtr(pIDirect3D11CaptureFramePool))
    Using this method you can actually stream the video in real time straight into a PictureBox. The following code streams 1 second of video (60 frames) into the PictureBox from the main form. It's as fluid as the actual video player:

    Code:
    Private Function StartCapture(ByVal pIGraphicsCaptureItem As Long) As Boolean
        Dim pIDirect3D11CaptureFramePool As Long, lFrames As Long
        lFrames = 60
        If Invoke(pIDirect3D11CaptureFramePoolStatics, IDirect3D11CaptureFramePoolStatics_Create, ObjPtr(objIDirect3DDevice), DXGI_FORMAT_B8G8R8A8_UNORM, lFrames, m_lWidth, m_lHeight, VarPtr(pIDirect3D11CaptureFramePool)) = S_OK Then
            Dim pIGraphicsCaptureSession As Long
            If Invoke(pIDirect3D11CaptureFramePool, IDirect3D11CaptureFramePool_CreateCaptureSession, pIGraphicsCaptureItem, VarPtr(pIGraphicsCaptureSession)) = S_OK Then
                Dim pIGraphicsCaptureSession2 As Long
                If Invoke(pIGraphicsCaptureSession, IUnknown_QueryInterface, pIID_IGraphicsCaptureSession_2, VarPtr(pIGraphicsCaptureSession2)) = S_OK Then
                    Call Invoke(pIGraphicsCaptureSession2, IGraphicsCaptureSession2_PutIsCursorCaptureEnabled, 0&)
                    Call Release(pIGraphicsCaptureSession2)
                End If
                Dim pIGraphicsCaptureSession3 As Long
                If Invoke(pIGraphicsCaptureSession, IUnknown_QueryInterface, pIID_IGraphicsCaptureSession_3, VarPtr(pIGraphicsCaptureSession3)) = S_OK Then
                    Call Invoke(pIGraphicsCaptureSession3, IGraphicsCaptureSession3_PutIsBorderRequired, 0&)
                    Call Release(pIGraphicsCaptureSession3)
                End If
                If Invoke(pIGraphicsCaptureSession, IGraphicsCaptureSession_StartCapture) = S_OK Then
                    Dim pIDirect3D11CaptureFrame As Long, i As Long
                    For i = 0 To lFrames - 1
                        While pIDirect3D11CaptureFrame = 0: Call Invoke(pIDirect3D11CaptureFramePool, IDirect3D11CaptureFramePool_TryGetNextFrame, VarPtr(pIDirect3D11CaptureFrame)): Wend
                        Dim pIDirect3DSurface As Long
                        If Invoke(pIDirect3D11CaptureFrame, IDirect3D11CaptureFrame_GetSurface, VarPtr(pIDirect3DSurface)) = S_OK Then
                            StartCapture = GetImageFromIDirect3DSurface(pIDirect3DSurface)
                            Call CloseAndRelease(pIDirect3DSurface)
                        End If
                        Call CloseAndRelease(pIDirect3D11CaptureFrame)
                        Set frmMain.picCapture.Picture = Picture
                    Next i
                End If
                Call CloseAndRelease(pIGraphicsCaptureSession)
            End If
            Call CloseAndRelease(pIDirect3D11CaptureFramePool)
        End If
    End Function

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width