问题描述
Cef浏览器方法:SetZoomLevel和GetZoomLevelAsync使用ZoomLevel,这是人类难以理解的:https://www.magpcss.org/ceforum/viewtopic.php?f=6&t=11491#p21763
我已经创建了扩展程序来解决此问题,它可能会帮助某人:
解决方法
public static class CefExtensions
{
/// <summary>
/// Converts the given percentage to the ZoomLevel to looke like chrome at zooming in/out
/// 100 (%) = No Zoom / Reset
/// </summary>
/// <param name="pPercentage">Default= 100 = reset zoom</param>
public static void SetZoomPercent(this ChromiumWebBrowser pBrowser,int pPercentage = 100)
{
var lTmp = pPercentage / 100f;
var lZoomLevel = Math.Log(lTmp,1.2);
pBrowser.SetZoomLevel(lZoomLevel);
}
/// <summary>
/// Translates the cef ZoomLevel to the Zoom showed at the Chrome Browser
/// Usage: Browser.GetZoomPercentAsync().Result
///</summary>
public static async Task<double> GetZoomPercentAsync(this ChromiumWebBrowser pBrowser)
{
var lZoomLevel = await pBrowser.GetZoomLevelAsync();
var lPercentage = Math.Pow(1.2,lZoomLevel) * 100;
return lPercentage;
}
}