Coder Social home page Coder Social logo

wangpy1995 / dxgi4py Goto Github PK

View Code? Open in Web Editor NEW
11.0 11.0 4.0 918 KB

Python DXGI截图。由于中文搜索引擎关于python dxgi的结果均不可用,自写一个c++库用于帮助有需要的人。可指定窗口以及截图区域,以numpy array方式返回结果。 解决DirectX游戏截图黑屏, 窗口被遮挡或在屏幕外导致的截图不完整等情况。

License: GNU Affero General Public License v3.0

C++ 78.31% C 9.79% Python 11.90%
dxgi python

dxgi4py's People

Contributors

wangpy1995 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dxgi4py's Issues

这段代码的作用是什么呢?

我在此处找到与本仓库相似的代码块,但没有pch.cpp第182行开始的代码,这段代码看起来是在等待gpu事件完成,这样会对截屏的性能有影响吗?

D3D11_QUERY_DESC queryDesc;
queryDesc.Query = D3D11_QUERY_EVENT;
queryDesc.MiscFlags = NULL;
ID3D11Query* pQuery;
winrt::check_hresult(d3dDevice->CreateQuery(&queryDesc, &pQuery));
d3dContext->Flush();
d3dContext->End(pQuery);
BOOL queryData;
while (S_OK != winrt::check_hresult(d3dContext->GetData(pQuery, &queryData, sizeof(BOOL), 0)))
{

}

多次调用grab捕获连续的视频,会有上下割裂的情况

这是我的测试代码:

import ctypes
import cv2
import time
import win32gui

import numpy as np

if __name__ == '__main__':
    dxgi = ctypes.CDLL("G:\\1\\repo\\dxgi4py\\x64\\Debug\\dxgi4py.dll")
    dxgi.grab.argtypes = (ctypes.POINTER(ctypes.c_ubyte), ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int)
    dxgi.grab.restype = ctypes.POINTER(ctypes.c_ubyte)
    # dxgi.grab.argtypes = (
    #     np.ctypeslib.ndpointer(dtype=np.uint8, ndim=3, flags='C_CONTIGUOUS'), ctypes.c_int, ctypes.c_int, ctypes.c_int,
    #     ctypes.c_int)
    # dxgi.grab.restype = np.ctypeslib.ndpointer(dtype=np.uint8, ndim=3, flags='C_CONTIGUOUS')

    hwnd = win32gui.FindWindow(None, "Ice.mp4 - PotPlayer")

    if hwnd == 0:
        raise Exception(f"Cannot find window with title")

    dxgi.init_dxgi(hwnd)

    left, top, right, bottom = win32gui.GetWindowRect(hwnd)
    shotLeft, shotTop = 0, 0
    height = bottom - top
    width = right - left

    imgs = []

    for i in range(20):
        shot = np.ndarray((height, width, 4), dtype=np.uint8)
        shotPointer = shot.ctypes.data_as(ctypes.POINTER(ctypes.c_ubyte))

        dxgi.grab(shotPointer, 0, 0, width, height)
        # dxgi.grab(shot, 0, 0, width, height)

        imgs.append(shot)
        time.sleep(0.05)

    for i in range(20):
        cv2.imwrite(f'tempcap4/{i}.png', imgs[i])
        cv2.waitKey(0)

抓取到的割裂的图像

ERROR

Traceback (most recent call last):
File ".\dxgi_sample.py", line 20, in
dxgi.init_dxgi(hwnd)
OSError: [WinError -529697949] Windows Error 0xe06d7363

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.