SplashScreen不能识别DPI吗?

时间:2015-08-28 18:20:00

标签: c# wpf splash-screen dpi

我不将我的App.xaml用作ApplicationDefinition 相反,我提供了自己的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();
}

在我的App Startup事件中,我摆脱了SplashScreen并使用Window显示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
}

这很有效,但问题是我的代码中第一个SplashScreenStaticSplash的缩放比例):
我的显示器以3840x2160px,175%DPI运行 图像(new SplashScreen("/Splash.png"))为400x200像素 启动屏幕模仿窗口设置为Width="400" Height="225"(ProgressBar为25px高)。

窗口正确缩放:当拍摄屏幕截图并使用某些图形程序进行测量时,它是700x394像素,是原始400x225像素的175%。

我提供给SplashScreen类的图像没有缩放。它仍然是真正的400x200px。

有没有机会让第一个SplashScreen dpi知道或手动缩放,最好是Main()中的第一件事?

1 个答案:

答案 0 :(得分:1)

你遇到了问题,问题是它 dpi-aware。如果不是,则DPI虚拟化会将窗口及其内容重新缩放175%。这也扩大了位图。倾向于令人反感,它变得模糊。

但是WPF应用程序是dpi感知的,PresentationCore的模块构造函数调用SetProcessDPIAware()。这使得窗户大了175%。但不是位图,你仍然可以看到400x200像素。不模糊,位图中的一个像素映射到一个显示像素,正是您想要的dpi感知应用程序。但当然现在太小了,不适合窗户。

您必须自己调整大小。这当然再现了DPI虚拟化产生的模糊性。没有得到fuzzies确实需要设计匹配dpi的位图。也许没有那么多关于闪屏的烦恼,只需选择没有精细细节且没有文字的设计。

相关问题