Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetWindowRect和GetClientRect获取窗口坐标错误 #11

Closed
a1oyss opened this issue Jun 1, 2021 · 15 comments
Closed

GetWindowRect和GetClientRect获取窗口坐标错误 #11

a1oyss opened this issue Jun 1, 2021 · 15 comments
Labels
bug Something isn't working

Comments

@a1oyss
Copy link

a1oyss commented Jun 1, 2021

这个是错误坐标下的截图
test
然后我在调试时改成spy++的坐标后再截图就是正确的
test1

python版本:3.9.4
Windwos版本:21H1

@NateScarlet
Copy link
Owner

第二张也不对 正确的是无外边框纯内容 466x828 大小的

日志发一下

我没用 python 3.9 测试过 不知道是不是这个问题

@a1oyss
Copy link
Author

a1oyss commented Jun 1, 2021

第二张也不对 正确的是无外边框纯内容 466x828 大小的

日志发一下

我没用 python 3.9 测试过 不知道是不是这个问题

INFO [2021-06-01 10:31:25]:auto_derby.window:58: width=466 height=828
INFO [2021-06-01 10:31:25]:auto_derby.window:60: already in wanted size
INFO [2021-06-01 10:31:25]:main:52: game window: 788770
INFO [2021-06-01 10:31:28]:auto_derby.template:186: no match: tmpl=('connecting.png', 'retry_button.png', 'nurturing_command_training.png', 'nurturing_fans_not_enough.png', 'nurturing_finish_button.png', 'nurturing_formal_race_banner.png', 'nurturing_race_next_button.png', 'nurturing_option1.png', 'green_next_button.png', 'nurturing_ura_finals.png', 'nurturing_gene_inherit.png')

@NateScarlet
Copy link
Owner

在这个页面这样显示是正常的 育成需要你手动选完卡进去之后才能自动

@a1oyss
Copy link
Author

a1oyss commented Jun 1, 2021

在这个页面这样显示是正常的 育成需要你手动选完卡进去之后才能自动

我也这样试过,但是问题是screenshot得到的图片是不正确的,识别不到按钮

@NateScarlet
Copy link
Owner

是不是因为你游戏画面没全部显示在屏幕里 我看你任务栏挡住了

我双屏都没问题 这个直接调用的是windows自己的API 应该不大可能出错

@NateScarlet
Copy link
Owner

第一张图的尺寸是对的 要不然就是 PIL.ImageGrab 的 bug

你在这里加个 print(locals()) 比较下坐标数据是不是对的 错的话是怎么错的

return ImageGrab.grab(bbox, True, True)

@NateScarlet
Copy link
Owner

NateScarlet commented Jun 1, 2021

https://stackoverflow.com/questions/25467288/pils-imagegrab-is-capturing-at-the-wrong-resolution
或者是因为你系统 DPI 设置?

Stack Overflow
I'm trying to get a full screen (1920 x 1080) capture using this code. The saved images are only 1536 x 864 though.

solution: As Mark pointed out below, Windows has scaling which can be changed via

@a1oyss
Copy link
Author

a1oyss commented Jun 1, 2021

https://stackoverflow.com/questions/25467288/pils-imagegrab-is-capturing-at-the-wrong-resolution
或者是因为你系统 DPI 设置?

Stack Overflow**PIL's ImageGrab is capturing at the wrong resolution**I'm trying to get a full screen (1920 x 1080) capture using this code.
The saved images are only 1536 x 864 though.
solution: As Mark pointed out below, Windows has scaling which can be changed via

解决了。。。,确实是分辨率问题,笔记本有125%缩放导致坐标获取有偏移,感谢

Stack Overflow
I'm trying to get a full screen (1920 x 1080) capture using this code. The saved images are only 1536 x 864 though.

solution: As Mark pointed out below, Windows has scaling which can be changed via

@NateScarlet
Copy link
Owner

NateScarlet commented Jun 1, 2021

不对 这个在pillow PR4000 里修了啊
https://github.com python-pillow Pillow/pull/4000
你是不是用的版本太老

GitHub
GitHub is where over 65 million developers shape the future of software, together. Contribute to the open source community, manage your Git repositories, review code like a pro, track bugs and feat...

@a1oyss
Copy link
Author

a1oyss commented Jun 1, 2021

不对 这个在pillow PR4000 里修了啊
https://github.com python-pillow Pillow/pull/4000
你是不是用的版本太老

GitHub**GitHub: Where the world builds software**GitHub is where over 65 million developers shape the future of software, together. Contribute to the open source community, manage your Git repositories, review code like a pro, track bugs and feat...

不是Pillow的原因,应该就是win32API的问题

GitHub
GitHub is where over 65 million developers shape the future of software, together. Contribute to the open source community, manage your Git repositories, review code like a pro, track bugs and feat...

@NateScarlet
Copy link
Owner

那我这边应该也处理下不同DPI

win32 应该有返回DPI缩放比率的

@a1oyss
Copy link
Author

a1oyss commented Jun 1, 2021

那我这边应该也处理下不同DPI

win32 应该有返回DPI缩放比率的

找到了一个解决方案
在__main__.py中添加
ctypes.windll.shcore.SetProcessDpiAwareness(2)
在缩放率125%的情况下是成功的,不知道其他缩放率下是否可以

@NateScarlet
Copy link
Owner

NateScarlet commented Jun 1, 2021

https://github.com/python-pillow/Pillow/pull/4000/files#diff-a592fb63b483610c48cce81b875ed7d27e5a68cfcbc289340cd1f0326f12a781R355

PIL 用的是 SetThreadDpiAwarenessContext 不知道(Handle)-3是什么意思

其实这个应该算 PIL bug 因为它确实有尝试支持不同的 DPI

GitHub
Fixes #2438 and its duplicates #3432, #3626 for Windows 10 version 1607+ (Anniversary Update). This PR uses SetThreadDpiAwarenessContext to temporarily make Python DPI aware. This function returns ...

@NateScarlet
Copy link
Owner

StackOverflow 回答下面有个用 SetProcessDPIAware 的

from ctypes import windll
windll.user32.SetProcessDPIAware()

@a1oyss
Copy link
Author

a1oyss commented Jun 1, 2021

StackOverflow 回答下面有个用 SetProcessDPIAware 的

from ctypes import windll
windll.user32.SetProcessDPIAware()

嗯,试过了,确实能行

@NateScarlet NateScarlet added the bug Something isn't working label Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants