如何解决将CefSharp 3 ZoomLevel转换为百分比,然后再次返回
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;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。