Skip to content

CefSharp for WPF gives blurry screenΒ #166

Closed

Description

@tronda

I'm running Windows 8 and have a simple demo project which includes Cef. When starting up Dropbox in Cef I get a blurry screen as shown in the screenshot attached. I've also included the preferences from Display settings in Control Panel.

I have NVidia graphic card and have NVIDIA Control Panel running, but cannot find any specific settings which should affect this, but I'm no graphics geek. The sample project can be attached if needed.

Running dropbox.com from Windows Forms gives no issues with regards to the display.

cefwpf_blur

display_prefs

Activity

  1. peters commented on Sep 11, 2013

    @peters
    Contributor

    I've noticed this myself, but this has mostly been caused by thirdparty fonts not being loaded properly. But on the second attempt (page reload) the bluryness was gone because the fonts loaded properly.

  2. tronda commented on Sep 11, 2013

    @tronda
    Author

    I've tried to navigate the dropbox site after initial load, but didn't impact the bluryness. I've included a cache when setting up Cef:

        var settings = new Settings
        {
            CachePath = "C:\\temp\\wpf_cef_cache",
            AutoDetectProxySettings = true,
            PackLoadingDisabled = true
         };
    
         CEF.Initialize(settings);

    I guess that if it was a cache issue, then the browser probably would cache the web font, but I might be mistaken.

  3. perlun commented on Sep 11, 2013

    @perlun
    Member

    I've managed to reproduce this now; I'd clearly say it's a bug. Let's see how hard it is to fix...

  4. perlun commented on Sep 12, 2013

    @perlun
    Member

    @tronda - please test the latest master. I managed to find a suitable workaround. It turned out to not be so easy, which is why you didn't see this comment yesterday already. πŸ˜‰ It was crazy, but it turned out to be a combination of two issues:

    • The fact that we were in fact rendering the Chromium content to a too small viewport (since we were giving Chromium the size of it in device-independent pixels, rather than "true pixels").
    • The fact that WPF uses this device-independent pixel system, and it's very hard to get rid of it.

    What I did was add a ScaleTransform on the image (inside the WebView), so that we "scale it down" to the actual size it should be... Crazy, yes, but this should in essence mean that WPF will detect that its a conversion from 100 too 100, so in reality it should mean that no conversion will take place.

    I encourage you to test this thoroughly. Preferably with both 100 and 125% settings applied. In the worst case, this will have performance implications (because of the above mentioned ScaleTransform) but in the best case, it will work well. Also, very important points: the mouse position we report to Chromium/CEF also had to be tweaked because of the transformation. I think I fixed it properly, but there's always a chance of some bug slipping in...

  5. tronda commented on Sep 13, 2013

    @tronda
    Author

    I will try to build CefSharp this weekend and try it out on my simple sample project. Thank you for resolving this so fast.

  6. jimbourekas commented on Oct 2, 2013

    @jimbourekas

    So is this resolved? Any news?
    jim

  7. tronda commented on Oct 2, 2013

    @tronda
    Author

    I have not had the time to test this, but it shouldn't take too much time since you can download the source, build it and run the example projects on a Win8 box with 125 size in the display as shown above. Alternatively you can try to modify it on a Win7 box.

  8. perlun commented on Oct 24, 2013

    @perlun
    Member

    Reopening since we need to get this one fixed for CefSharp3 also.

  9. reopened this on Oct 24, 2013
  10. perlun commented on Mar 20, 2014

    @perlun
    Member

    Closing now that #281 has been merged. Thank you, @JanEggers!

  11. modified the milestones: , 33.0.0 on Mar 25, 2014
  12. whitezaz commented on Oct 28, 2014

    @whitezaz

    Hello guys,

    it seems like this issue came back, at least, for me. What I've done is just started WPF example on my Windows 8.1 (resolution 3200x1800, scaling 250%). Please, take a look on blurry fonts:
    cefsharp - example

    my scaling settings:
    dpi

    Have you any ideas what is this?

    Thanks in advance!

  13. CaptainBli commented on Feb 25, 2015

    @CaptainBli

    Any zoom at all causes the same symptoms with the current stable build of 37.0.0. Is there a way to tell the renderer to use a larger size canvas on initialization?

  14. gengjiawen commented on Aug 24, 2016

    @gengjiawen

    Win10, 4K resolution has the same issue.

  15. tshcherban commented on Sep 19, 2016

    @tshcherban

    I've found this happens when a browser control gets a non-integer coordinate relative to the window (e.g. 10.5 instead of 10). I fixed it by putting the browser control on a canvas and adding a Canvas.SizeChanged event handler:

        private void Canvas_OnSizeChanged(object sender, SizeChangedEventArgs e)
        {
            var canvasPosition = Canvas1.TransformToAncestor(Application.Current.MainWindow).Transform(new Point(0, 0));
    
            var x = 1 - Math.Abs((int)canvasPosition.X - canvasPosition.X);
            var y = 1 - Math.Abs((int)canvasPosition.Y - canvasPosition.Y);
    
            Canvas.SetLeft(browser, x);
            Canvas.SetTop(browser, y);
    
            browser.Height = Math.Round(e.NewSize.Height);
            browser.Width = Math.Round(e.NewSize.Width);
        }
    

    maybe we can just add similar trick to control and align rendered image?

  16. feinstein commented on Nov 15, 2016

    @feinstein

    I fixed this problem by setting the control XAML tag as:

            <cefsharp:ChromiumWebBrowser RenderOptions.BitmapScalingMode="HighQuality" >
    

    AND using UseLayoutRounding="True" on the root container of my XAML (which is a Grid). Without the UseLayoutRounding="True" the image gets a little blurred.

    Keep in min UseLayoutRounding="True" will disable antialiasing for all the code inside it, if you don't want it, try to wrap your control inside multiple grids and change UseLayoutRounding="True" to "False" accordingly to select which parts of your UI should have antialiasing and which shouldn't.

  17. MarcBra commented on Sep 13, 2017

    @MarcBra

    I've had issues with blurry page rendering also. Turned out to be caused by setting FontFamily on a TextBox control in the same WPF window. I don't understand why, but it might help to check the fonts if you're experiencing the issues...

  18. Ganeshcse commented on Nov 4, 2019

    @Ganeshcse

    I've found this happens when a browser control gets a non-integer coordinate relative to the window (e.g. 10.5 instead of 10). I fixed it by putting the browser control on a canvas and adding a Canvas.SizeChanged event handler:

        private void Canvas_OnSizeChanged(object sender, SizeChangedEventArgs e)
        {
            var canvasPosition = Canvas1.TransformToAncestor(Application.Current.MainWindow).Transform(new Point(0, 0));
    
            var x = 1 - Math.Abs((int)canvasPosition.X - canvasPosition.X);
            var y = 1 - Math.Abs((int)canvasPosition.Y - canvasPosition.Y);
    
            Canvas.SetLeft(browser, x);
            Canvas.SetTop(browser, y);
    
            browser.Height = Math.Round(e.NewSize.Height);
            browser.Width = Math.Round(e.NewSize.Width);
        }
    

    maybe we can just add similar trick to control and align rendered image?

    I tried this approach, when my window is launched the content of the browser is blurry. But when I tried resizing at certain coordinates the content becomes clear. But is there any way to get this effect on window load. Since my window cannot resize. Its a modal dialog.

    I know its been more than 2 years that this thread is in-active.

  19. tshcherban commented on Nov 4, 2019

    @tshcherban

    @Ganeshcse
    i think you can put this code to 'Loaded' event, maybe via dispatcher with some low priority to wait until content loads. Or (high chance) you'll need to use some html DOM's event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcef3wpf

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions