如何在UWP应用程序中将GIF图片制作为SplashScreen?

如何在UWP应用程序中将GIF图片制作为SplashScreen?,uwp,Uwp,我想在UWP应用程序中使用GIF图片(带动画)作为启动屏幕。但我不知道如何实现它。我找到一些链接来提供一些解决方案,但似乎它们不适用于UWP应用程序。像这个: App.xaml.cs: protected override void OnLaunched(LaunchActivatedEventArgs e) { if (e.PreviousExecutionState != ApplicationExecutionState.Runni

我想在UWP应用程序中使用GIF图片(带动画)作为启动屏幕。但我不知道如何实现它。我找到一些链接来提供一些解决方案,但似乎它们不适用于UWP应用程序。像这个:

App.xaml.cs:

        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            if (e.PreviousExecutionState != ApplicationExecutionState.Running)
            {
                bool loadState = (e.PreviousExecutionState == ApplicationExecutionState.Terminated);
                ExtendedSplash extendedSplash = new ExtendedSplash(e.SplashScreen, loadState);
                Window.Current.Content = extendedSplash;
            }

            Window.Current.Activate();
        }
ExtendedSplash.xaml:

<Page
x:Class="SplashScreenExample.ExtendedSplash"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SplashScreenExample"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="#464646">
    <Image x:Name="extendedSplashImage" Source="Assets/test.gif"/>
</Grid>

ExtendedSplash.xaml.cs:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.ApplicationModel.Activation;
using Windows.UI.Core;
using System.Diagnostics;
using Windows.UI.ViewManagement;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace SplashScreenExample
{
    partial class ExtendedSplash : Page
    {
        internal Rect splashImageRect; // Rect to store splash screen image coordinates.
        private SplashScreen splash; // Variable to hold the splash screen object.
        internal bool dismissed = false; // Variable to track splash screen dismissal status.
        internal Frame rootFrame;

        // Define methods and constructor
        public ExtendedSplash(SplashScreen splashscreen, bool loadState)
        {
            InitializeComponent();

            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;

            splash = splashscreen;
            if (splash != null)
            {
                // Register an event handler to be executed when the splash screen has been dismissed.
                splash.Dismissed += new TypedEventHandler<SplashScreen, Object>(DismissedEventHandler);

                // Retrieve the window coordinates of the splash screen image.
                splashImageRect = splash.ImageLocation;
                splashImageRect.Width = 1092;
                splashImageRect.Height = 1080;
                splashImageRect.X = 0;
                splashImageRect.Y = 0;
            }

            // Create a Frame to act as the navigation context
            rootFrame = new Frame();
        }

        // Include code to be executed when the system has transitioned from the splash screen to the extended splash screen (application's first view).
        void DismissedEventHandler(SplashScreen sender, object e)
        {
            dismissed = true;

            // Complete app setup operations here...
        }

        void DismissExtendedSplash()
        {
            // Navigate to mainpage
            rootFrame.Navigate(typeof(MainPage));
            // Place the frame in the current Window
            Window.Current.Content = rootFrame;
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.IO;
使用System.Linq;
使用System.Runtime.InteropServices.WindowsRuntime;
使用Windows基金会;
使用Windows。
使用Windows.UI.Xaml;
使用Windows.UI.Xaml.Controls;
使用Windows.UI.Xaml.Controls.Primitives;
使用Windows.UI.Xaml.Data;
使用Windows.UI.Xaml.Input;
使用Windows.UI.Xaml.Media;
使用Windows.UI.Xaml.Navigation;
使用Windows.ApplicationModel.Activation;
使用Windows.UI.Core;
使用系统诊断;
使用Windows.UI.ViewManagement;
//空白页项模板被记录在https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
名称空间示例
{
分部类ExtendedSplash:第页
{
内部Rect splashImageRect;//用于存储启动屏幕图像坐标的Rect。
private SplashScreen splash;//用于保存启动屏幕对象的变量。
内部bool disposed=false;//用于跟踪初始屏幕解雇状态的变量。
内部框架根框架;
//定义方法和构造函数
公共扩展Splash(SplashScreen SplashScreen,bool loadState)
{
初始化组件();
ApplicationView.PreferredLaunchWindowingMode=ApplicationViewWindowingMode.FullScreen;
飞溅=飞溅屏幕;
如果(飞溅!=null)
{
//注册一个事件处理程序,当启动屏幕被取消时执行。
splash.disposed+=新类型的Deventhandler(DismissedEventHandler);
//检索启动屏幕图像的窗口坐标。
splashImageRect=splash.ImageLocation;
splashImageRect.Width=1092;
splashImageRect.高度=1080;
splashImageRect.X=0;
splashImageRect.Y=0;
}
//创建一个框架作为导航上下文
rootFrame=新框架();
}
//包括系统从初始屏幕转换到扩展初始屏幕(应用程序的第一个视图)时要执行的代码。
void dismissedenthandler(飞溅屏幕发送器,对象e)
{
驳回=正确;
//在此处完成应用程序安装操作。。。
}
void DismissExtendedSplash()
{
//导航到主页
rootFrame.Navigate(typeof(MainPage));
//将框架放置在当前窗口中
Window.Current.Content=rootFrame;
}
}
}

请检查“设定如何扩展飞溅”,您可以使用Gif图像自定义飞溅。有关完整的代码示例,请检查此项。

谢谢您的帮助!我检查了你的链接并制作了一个新的演示,它可以工作!但我遇到了一些新的问题,这是在我的主线程更新,请检查它。谢谢这5秒是默认启动,请检查默认启动图像路径是否正确,请不要。您无法删除默认启动。我在Package.appxmanifest中注释掉默认启动屏幕png文件。你的意思是这一步是硬编码的,所以我们不能删除它?是的,默认的闪屏无法删除。更好的方法是使默认闪屏图像与gif图像相同,并设置闪屏背景。
<Page
x:Class="SplashScreenExample.ExtendedSplash"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SplashScreenExample"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="#464646">
    <Image x:Name="extendedSplashImage" Source="Assets/test.gif"/>
</Grid>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.ApplicationModel.Activation;
using Windows.UI.Core;
using System.Diagnostics;
using Windows.UI.ViewManagement;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace SplashScreenExample
{
    partial class ExtendedSplash : Page
    {
        internal Rect splashImageRect; // Rect to store splash screen image coordinates.
        private SplashScreen splash; // Variable to hold the splash screen object.
        internal bool dismissed = false; // Variable to track splash screen dismissal status.
        internal Frame rootFrame;

        // Define methods and constructor
        public ExtendedSplash(SplashScreen splashscreen, bool loadState)
        {
            InitializeComponent();

            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;

            splash = splashscreen;
            if (splash != null)
            {
                // Register an event handler to be executed when the splash screen has been dismissed.
                splash.Dismissed += new TypedEventHandler<SplashScreen, Object>(DismissedEventHandler);

                // Retrieve the window coordinates of the splash screen image.
                splashImageRect = splash.ImageLocation;
                splashImageRect.Width = 1092;
                splashImageRect.Height = 1080;
                splashImageRect.X = 0;
                splashImageRect.Y = 0;
            }

            // Create a Frame to act as the navigation context
            rootFrame = new Frame();
        }

        // Include code to be executed when the system has transitioned from the splash screen to the extended splash screen (application's first view).
        void DismissedEventHandler(SplashScreen sender, object e)
        {
            dismissed = true;

            // Complete app setup operations here...
        }

        void DismissExtendedSplash()
        {
            // Navigate to mainpage
            rootFrame.Navigate(typeof(MainPage));
            // Place the frame in the current Window
            Window.Current.Content = rootFrame;
        }
    }
}