我想将GIF图片(带有动画)用作UWP应用程序中的启动画面。但是我不知道如何实现它。我找到一些链接来提供一些解决方案,但似乎它们不适用于UWP应用。像这个: https://social.msdn.microsoft.com/Forums/en-US/3fe32aae-84cb-47fe-a2b0-6650ce22e25c/splashscreen-that-loads-an-animated-gif?forum=vssmartdevicesvbcs
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="Assets\SplashScreen.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;
}
}
}
答案 0 :(得分:1)
请选中https://doc.qt.io/qt-5/qabstractitemmodel.html#beginInsertRows,其中介绍了如何扩展初始画面,您可以使用Gif图像自定义初始画面。有关完整的代码示例,请选中此Display a splash screen for more time。