kivy 应用在 windows 高分辨率屏幕上模糊不清

kivy app is blurry on windows with high resolution screen

我的 kivy 应用程序有问题。在我的高分辨率 windows 笔记本电脑 (3840x2160) 上,文字很模糊。它在 Mac 视网膜显示屏和 windows 较低分辨率的 PC 上运行良好。如以下屏幕截图所示。

这是我的测试代码:

import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.config import Config
Config.set('graphics', 'width', '200')
Config.set('graphics', 'height', '100')

class MyApp(App):
    def build(self):
        return Label(text="why is this blurry")

if __name__ == "__main__":
    MyApp().run()

这是控制台输出:

[INFO   ] [Logger      ] Record log in C:\Users\lucas\.kivy\logs\kivy_22-04-01_6.txt
[INFO   ] [deps        ] Successfully imported "kivy_deps.angle" 0.3.2
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.3.1
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.4.5
[INFO   ] [Kivy        ] v2.1.0
[INFO   ] [Kivy        ] Installed at "C:\Users\lucas\kivytest\env\lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.9.10 (tags/v3.9.10:f2f3f53, Jan 17 2022, 15:14:21) [MSC v.1929 64 bit (AMD64)][INFO   ] [Python      ] Interpreter at "C:\Users\lucas\kivytest\env\Scripts\python.exe"       
[INFO   ] [Logger      ] Purge log fired. Processing...
[INFO   ] [Logger      ] Purge finished!
[INFO   ] [Factory     ] 189 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2 (img_pil, img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] GLEW initialization succeeded
[INFO   ] [GL          ] Backend used <glew>
[INFO   ] [GL          ] OpenGL version <b'4.6.14757 Compatibility Profile Context FireGL 20.45.01.45 27.20.14501.45003'>
[INFO   ] [GL          ] OpenGL vendor <b'ATI Technologies Inc.'>
[INFO   ] [GL          ] OpenGL renderer <b'AMD Radeon(TM) Pro Graphics'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 6
[INFO   ] [GL          ] Shading version <b'4.60'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Base        ] Start application main loop
[INFO   ] [GL          ] NPOT texture support is available

这个问题似乎与此有关:https://github.com/kivy/kivy/issues/3705

或者这个:https://github.com/kivy/kivy/pull/7299

或者这个:https://github.com/kivy/kivy/pull/7293

但是 none 的建议似乎对我有用。知道如何解决这个问题吗?

解决方案基本上在我发布的第二个 link 中:https://github.com/kivy/kivy/pull/7299

当我在这里没有得到任何回复时,我也在该线程中发布了一个问题,但会在此处复制我的解决方案。

当我执行以下操作时:

from ctypes import windll
windll.user32.SetProcessDpiAwarenessContext(-4)
lastError = windll.kernel32.GetLastError()
print(lastError)

我得到了对应于 ERROR_INVALID_PARAMETER 的错误 87。所以 -4 一定有问题。我在 windll 周围挖掘并发现了以下修复:

from ctypes import windll, c_int64
windll.user32.SetProcessDpiAwarenessContext(c_int64(-4))

您发布的第二个 link 提供了以下信息:

from ctypes import windll
windll.user32.SetProcessDpiAwarenessContext(-4)

现在这不起作用,所以我们必须添加 c_int64,在同一模块中找到的东西。

from ctypes import windll, c_int64
windll.user32.SetProcessDpiAwarenessContext(c_int64(-4))

现在可以使用了!

编辑:我之前没有意识到你已经想通了!