weolar / miniblink49

a lighter, faster browser kernel of blink to integrate HTML UI in your app. 一个小巧、轻量的浏览器内核,用来取代wke和libcef
Apache License 2.0
7.22k stars 1.09k forks source link

文字显示模糊 #513

Open shengxq opened 3 years ago

shengxq commented 3 years ago

直接上图片对比效果了 版本 miniblink-20210831 https://sydcdn.oss-cn-beijing.aliyuncs.com/Snipaste_2021-11-21_07-10-02.png

shengxq commented 3 years ago

点这里看图片

yuewe commented 1 month ago

我用的python MBPython调用的miniblink 也会模糊,参考其他问题里面的思路是先随界面分辨率缩小,再用zoom放大,然后就正常了,代码如下:

from MBPython import miniblink
import win32api, win32gui, win32print
from win32.lib import win32con
from  win32api import GetSystemMetrics
import ctypes

# 设置进程DPI感知
# ctypes.windll.user32.SetProcessDPIAware(0)

# ctypes.windll.shcore.SetProcessDpiAwareness(1)

def get_real_resolution():
    """获取真实的分辨率"""
    hDC = win32gui.GetDC(0)
    # 横向分辨率
    w = win32print.GetDeviceCaps(hDC, win32con.DESKTOPHORZRES)
    # 纵向分辨率
    h = win32print.GetDeviceCaps(hDC, win32con.DESKTOPVERTRES)
    return w, h

def get_screen_size():
    """获取缩放后的分辨率"""
    w = GetSystemMetrics (0)
    h = GetSystemMetrics (1)
    return w, h

def getdpi():

    real_resolution = get_real_resolution()
    screen_size = get_screen_size()

    screen_scale_rate = round(real_resolution[0] / screen_size[0], 2)
    screen_scale_rate = screen_scale_rate * 100
    return screen_scale_rate

userdpi = getdpi()
print('当前系统缩放率为:',userdpi,'%',end='')

print(get_real_resolution())
print(get_screen_size())
# user32 = ctypes.windll.user32

# print(user32.GetDpiForSystem())
# SCALE_FACTOR = user32.GetDpiForSystem() / 96.0
# print(SCALE_FACTOR)

# import win32api
#
# SCALE_FACTOR = win32api.GetSystemMetrics(78) / 96.0
# print(SCALE_FACTOR)

# import win32com.client
#
# shell = win32com.client.Dispatch("WScript.Shell")
SCALE_FACTOR = userdpi/100.0
# SCALE_FACTOR = shell.RegRead("HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\AppliedDPI")
print(SCALE_FACTOR)

'''
------------------------
第一步
ctypes.windll.shcore.SetProcessDpiAwareness(1)
----------------------
'''
ctypes.windll.shcore.SetProcessDpiAwareness(1)

mbpython=miniblink.Miniblink
mb=mbpython.init(r'D:\workspaces\rpa\blink-python\miniblink_4975_x64.dll')
wke=mbpython(mb)
window=wke.window

webview=window.wkeCreateWebWindow(0,0,0,0,860,760)

'''
第二步
window.wkeSetZoomFactor(webview,SCALE_FACTOR)
'''
window.wkeSetZoomFactor(webview,SCALE_FACTOR)

window.wkeShowWindow(webview)

network=wke.network
network.wkeLoadURLW(webview,'https://www.baidu.com/')
window.wkeRunMessageLoop()