将ImageGrab与pywin32的GetWindowRect中的bbox一起使用 [英] Using ImageGrab with bbox from pywin32's GetWindowRect

查看:129
本文介绍了将ImageGrab与pywin32的GetWindowRect中的bbox一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用PIL的ImageGrab捕获特定的窗口.我下面的代码所做的是,它使用pywin32的FindWindow获取所需窗口的句柄,然后使用GetWindowRect获取其大小和位置.然后,我将ImageGrab与bbox一起使用,该bbox等于我从GetWindowRect获得的结果.但是,这不能捕获整个窗口.窗口的很大一部分没有显示.我做错什么了?这是我的代码和得到的结果:

I want to use PIL's ImageGrab to capture a specific window. What my code below does is that it uses pywin32's FindWindow to get the handle of my wanted window then get its size and location with GetWindowRect. I then use ImageGrab with a bbox equal to the result that I got from GetWindowRect. However, this does not capture the whole window; a big chunk of the window is not shown. What did I do wrong? Here is my code and the result I get:

import win32gui
import cv2
from PIL import ImageGrab
import numpy as np

fceuxHWND = win32gui.FindWindow(None, 'FCEUX 2.1.4a: Super Mario Bros. (JU) 
[!]')
rect = win32gui.GetWindowRect(fceuxHWND)
screen = np.array(ImageGrab.grab(bbox=rect), dtype=np.uint8)

cv2.imshow('test',cv2.cvtColor(screen,cv2.COLOR_BGR2RGB))

代码结果

推荐答案

您的DPI设置为125%,并且您的过程不支持DPI.如下调用SetProcessDPIAware

Your DPI settings is at 125% and your process is not DPI aware. Call SetProcessDPIAware as follows

import ctypes
...
ctypes.windll.user32.SetProcessDPIAware()

这篇关于将ImageGrab与pywin32的GetWindowRect中的bbox一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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