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



我想在UWP应用程序中使用GIF图片(带有动画(作为我的飞溅屏幕。但是我不知道如何实现它。我发现一些链接可以提供一些解决方案,但似乎它们不适合UWP应用程序。像这个:https://social.msdn.microsoft.com/forums/en-us/3fe32aae-84cb-47fe-a2b0-a2b0-6650ce225c/splashscreen-that-loads-loads-an-that-loads-an-an-an-an-an-animimated-gif gorum = forum = forum = forum = vssmartdevicevbcsvbcsvbcsvbcsvbcs

private void Form1_Load(object sender, EventArgs e)
    {    
        String imgPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString()) + "\Ani.gif"; 
        StringBuilder sb = new StringBuilder();
        sb.Append("<html><body>");
        sb.Append("<img src = "" + imgPath + "">");
        sb.Append("</body></html>");
        webBrowser1.DocumentText = sb.ToString();
    }

您对UWP应用程序有可行的解决方案吗?请指教。谢谢!

更多:

通过检查朱先生给出链接,我做了一个gif飞溅屏幕,它可以正常工作。但是有新问题:在GIF显示之前,可能会有5s白屏。如何删除它?新的测试代码如下:

Package.appxmanifest:评论原始的飞溅屏幕png文件

 <!--<uap:SplashScreen Image="AssetsSplashScreen.png" />-->

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;
        }
    }
}

请检查显示更多时间教授如何扩展飞溅的时间,您可以使用GIF映像自定义溅起。有关完整的代码示例,请检查此链接。

最新更新