Przeglądaj źródła

fix(device) window high scale rate causes the screenshot size to be incorrect

runhey 3 lat temu
rodzic
commit
50f75baf8b

+ 13 - 3
module/device/handle.py

@@ -295,14 +295,24 @@ class Handle:
         return None
         return None
 
 
     @cached_property
     @cached_property
-    def screenshot_size(self) -> tuple:
+    def screenshot_size(self) -> tuple or None:
         """
         """
         第一个是width 第二个是heigth
         第一个是width 第二个是heigth
+        2023.7.1 在高缩放的设备上应该输出1280X720
         :return:
         :return:
         """
         """
         winRect = GetWindowRect(self.screenshot_handle_num)
         winRect = GetWindowRect(self.screenshot_handle_num)
-        width: int = winRect[2] - winRect[0]  # 右x-左x
-        height: int = winRect[3] - winRect[1]  # 下y - 上y 计算高度
+        scale_rate = window_scale_rate()
+        width_before: int = winRect[2] - winRect[0]  # 右x-左x
+        height_before: int = winRect[3] - winRect[1]  # 下y - 上y 计算高度
+        width, height = None, None
+        if abs((width_before * scale_rate) - 1280) < 5:
+            width = 1280
+        if abs((height_before * scale_rate) - 720) < 5:
+            height = 720
+        if width is None or height is None:
+            logger.error(f'Get screenshot size error, width={width}, height={height}')
+            return None
         return width, height
         return width, height
 
 
     @cached_property
     @cached_property

+ 1 - 4
module/device/method/window.py

@@ -38,10 +38,7 @@ class Window(Handle):
         后台截屏
         后台截屏
         :return:
         :return:
         """
         """
-        win_size = self.screenshot_size
-        scale_rate = window_scale_rate()
-        widthScreen = int(win_size[0] * scale_rate)
-        heightScreen = int(win_size[1] * scale_rate)
+        widthScreen, heightScreen = self.screenshot_size
         # 返回句柄窗口的设备环境,覆盖整个窗口,包括非客户区,标题栏,菜单,边框
         # 返回句柄窗口的设备环境,覆盖整个窗口,包括非客户区,标题栏,菜单,边框
         hwndDc = GetWindowDC(self.screenshot_handle_num)
         hwndDc = GetWindowDC(self.screenshot_handle_num)
         # 创建设备描述表
         # 创建设备描述表

+ 2 - 2
script.py

@@ -444,5 +444,5 @@ class Script:
 if __name__ == "__main__":
 if __name__ == "__main__":
     script = Script("oas1")
     script = Script("oas1")
     # print(script.get_next_task())
     # print(script.get_next_task())
-    # script.run("ActivityShikigami")
-    script.run('RealmRaid')
+    script.run("ActivityShikigami")
+    # script.run('RealmRaid')

+ 3 - 0
tasks/Component/GeneralInvite/general_invite.py

@@ -0,0 +1,3 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey