如何在Awesomium中禁用图像加载?

时间:2013-09-11 13:41:38

标签: c# .net winforms awesomium

如何在屏幕外渲染模式下禁用浏览器Awesomium中的图像加载?

2 个答案:

答案 0 :(得分:1)

您可以在创建WebSession时关闭图像加载:

WebView.WebSession = WebCore.CreateWebSession(new WebPreferences(){LoadImagesAutomatically = false});

答案 1 :(得分:1)

您也可以使用ResourceInterceptor。优点:可以在不重新创建WebSession + WebControl / WebView的情况下进行切换。

public class ResourceInterceptor : IResourceInterceptor
{
    public bool NoImages { get; set; }

    private static string[] _imagesFileTypes = { ".png", ".jpg", ".jpeg", ".gif", ".bmp" };

    public ResourceResponse OnRequest(ResourceRequest request)
    {
        string ext = System.IO.Path.GetExtension(request.Url.ToString()).ToLower();

        if (NoImages && _imagesFileTypes.Contains(ext))
        {
            request.Cancel();
        }

        return null;
    }

    public bool OnFilterNavigation(NavigationRequest request)
    {
        return false;
    }
}


...

ResourceInterceptor ResInt = new ResourceInterceptor();
WebCore.ResourceInterceptor = ResInt;