简体   繁体   中英

Is SplashScreen not DPI aware?

I don't use my App.xaml as ApplicationDefinition .
Instead, I provide my own Main() :

public static SplashScreen StaticSplash = new SplashScreen("/Splash.png");

[STAThread]
static void Main(string[] args)
{
    StaticSplash.Show(autoClose: false, topMost: true);

    //... more code

    App application = new App();
    application.InitializeComponent();
    application.Run();
}

In my App s Startup event I get rid of my SplashScreen and show a Window mimicking splash-screen behaviour with a ProgressBar :

private void Application_Startup(object sender, StartupEventArgs e)
{
    //the following SplashScreen class is a Window
    UI.SplashScreen.SplashScreen sScr = new UI.SplashScreen.SplashScreen();
    sScr.ProgressBar.Maximum = 1d;
    sScr.Show();
    Program.StaticSplash.Close(new TimeSpan(0));

    //... even more code
}

This works quite well, but the problem is the scaling of the first SplashScreen ( StaticSplash in my code):
My monitor runs at 3840x2160px, 175% DPI.
The image ( new SplashScreen("/Splash.png") ) is 400x200 px.
The splash-screen mimicking Window is set to Width="400" Height="225" (ProgressBar is 25px high).

The Window gets scaled correctly: when taking a screenshot and measuring with some graphics program it's 700x394px, 175% of the original 400x225px.

The image I provide to the SplashScreen class gets not scaled. It remains at true 400x200px.

Is there any chance to make the first SplashScreen dpi aware or scale it manually, preferably as the very first thing in Main() ?

You got the problem backwards, the problem is that it is dpi-aware. If it wasn't then DPI virtualization would rescale the window and its content by 175%. Which also enlarges the bitmap. Tends to be objectionable, it gets fuzzy.

But a WPF app is dpi-aware, the module constructor of PresentationCore calls SetProcessDPIAware(). Which makes the window bigger by 175%. But not the bitmap, you still see it at 400x200 pixels. Not fuzzy, one pixel in the bitmap maps to one display pixel, just what you want out of a dpi-aware app. But of course now too small to fit the window.

You'll have to resize it yourself. Which of course reproduces the fuzziness that DPI virtualization produces. Not getting the fuzzies does require bitmaps that are designed to match the dpi. Perhaps not that much to fret about for a splash screen, just pick a design without fine detail and no text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM