Compare commits

...

2 Commits

Author SHA1 Message Date
ltx
eef77b8995 Merge branch 'dev' of http://8.153.108.90:3000/YD/Wpf_AiSportsMicrospace into dev 2025-10-16 20:56:24 +08:00
ltx
458e0ceac8 update:倒计时 2025-10-16 20:56:18 +08:00
9 changed files with 220 additions and 19 deletions

View File

@ -1,11 +1,15 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using WpfAnimatedGif;
namespace Wpf_AiSportsMicrospace.Common
{
@ -91,5 +95,118 @@ namespace Wpf_AiSportsMicrospace.Common
});
return total;
}
//public static Uri countDownGif = new Uri("/Resources/Img/Album/1.gif", UriKind.Relative);
//倒计时动画
public static Grid GetCountdownAnimation(Grid needAnimationGrid)
{
//string projectRoot = Path.Combine(AppContext.BaseDirectory, @"..\..\..");
//string gifPath = Path.Combine(projectRoot, "Resources", "Img", "gif" , "time_3.gif");
//var uri = new Uri(gifPath, UriKind.Absolute);
//var uri = new Uri("/Resources/Img/gif/time_3.gif", UriKind.Relative);
BitmapImage uri = GetGif("/time_3.gif");
var grid = new Grid
{
Height = 1080,
Width = 1920,
Name = "countdownGridAnimation",
};
var border = new Border
{
Height = 1080,
Width = 1920,
Background = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)), // 半透明黑色背景
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
grid.Children.Add(border);
var image = new System.Windows.Controls.Image
{
Source = uri,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Width = 1920,
Height = 1080,
};
ImageBehavior.SetAnimatedSource(image, uri);
ImageBehavior.SetAutoStart(image , true);
grid.Children.Add(image);
needAnimationGrid.Children.Add(grid);
Debug.WriteLine($"GIF尺寸: {uri.PixelWidth}x{uri.PixelHeight}");
Debug.WriteLine($"GIF URI: {uri.UriSource}");
// 动画播放完成后移除Grid
Task.Run(async () =>
{
await Task.Delay(3300); // 等待4秒钟确保动画播放完毕
Application.Current.Dispatcher.Invoke(() =>
{
needAnimationGrid.Children.Remove(grid);
});
});
return grid;
}
//预加载资源
private static readonly Dictionary<string, BitmapImage> _cache = new Dictionary<string, BitmapImage>();
private static bool _isPreloaded = false;
// 预加载所有需要的 GIF
public static void PreloadGifs()
{
if (_isPreloaded) return;
var gifPaths = new[]
{
"/time_3.gif",
// 添加其他需要预加载的 GIF 路径
};
foreach (var path in gifPaths)
{
LoadGifToCache(path);
}
_isPreloaded = true;
}
private static void LoadGifToCache(string relativePath)
{
try
{
string projectRoot = Path.Combine(AppContext.BaseDirectory, @"..\..\..");
string topPath = Path.Combine(projectRoot, "Resources", "Img", "gif");
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri(topPath + relativePath, UriKind.Relative);
bitmapImage.CacheOption = BitmapCacheOption.OnLoad; // 立即加载到内存
bitmapImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache; // 忽略磁盘缓存
bitmapImage.EndInit();
bitmapImage.Freeze(); // 冻结对象,使其线程安全
_cache[relativePath] = bitmapImage;
}
catch (Exception ex)
{
Debug.WriteLine($"预加载GIF失败 {relativePath}: {ex.Message}");
}
}
public static BitmapImage GetGif(string relativePath)
{
if (_cache.TryGetValue(relativePath, out var cachedImage))
{
return cachedImage;
}
// 如果缓存中没有,立即加载
LoadGifToCache(relativePath);
return _cache.GetValueOrDefault(relativePath);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

@ -16,6 +16,7 @@
VerticalAlignment="Top"
Width="615"
Margin="0,50,0,0"
MouseDown="Image_MouseDown"
/>
<!-- CoverFlowControl距离图片80 -->

View File

@ -36,6 +36,8 @@ namespace Wpf_AiSportsMicrospace
public partial class Home : UserControl
{
public static Uri loadingImage = new Uri("/Resources/Img/Album/1.gif", UriKind.Relative);
public static Uri countDownGif = new Uri("/Resources/Img/gif/time_3.gif", UriKind.Relative);
private Main _mainWin => Application.Current.MainWindow as Main;
public Home()
@ -61,6 +63,7 @@ namespace Wpf_AiSportsMicrospace
{
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
_mainWin.WebcamClient.StartExtract();
Utils.PreloadGifs();
}
private void Home_Unloaded(object sender, RoutedEventArgs e)
{
@ -163,5 +166,11 @@ namespace Wpf_AiSportsMicrospace
mainWin?.SwitchPageWithMaskAnimation(newPage, true);
}
}
private void Image_MouseDown(object sender, MouseButtonEventArgs e)
{
var mainWin = Application.Current.MainWindow as Main;
mainWin!.ShowCountDownAnimation();
}
}
}

View File

@ -4,6 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Wpf_AiSportsMicrospace.MyUserControl"
xmlns:gif="http://wpfanimatedgif.codeplex.com"
mc:Ignorable="d" Height="1080" Width="1920" Loaded="UserControl_Loaded" Unloaded="UserControl_Unloaded">
<Grid>
<Grid.Background>
@ -138,5 +139,5 @@
</Grid>
</Grid>
</Grid>
</Grid>
</Grid>
</UserControl>

View File

@ -220,12 +220,13 @@ namespace Wpf_AiSportsMicrospace.Views
private DateTime _lastUpdateTime = DateTime.Now;
private void StartCountdown(int start = 3)
{
_currentCountdown = start;
_mainWin.ShowCountDownAnimation();
//_currentCountdown = start;
countdownText.Text = _currentCountdown.ToString();
countdownGrid.Visibility = Visibility.Visible;
//countdownText.Text = _currentCountdown.ToString();
//countdownGrid.Visibility = Visibility.Visible;
_lastUpdateTime = DateTime.Now;
//_lastUpdateTime = DateTime.Now;
Utils.PlayBackgroundMusic("countdown_3.mp3", false);
}
@ -630,24 +631,43 @@ namespace Wpf_AiSportsMicrospace.Views
grid.Children.Add(scoreText);
ScoreGrid.Children.Add(grid);
}
showElement("RankingGrid");
//var rankingGrid = FindName("RankingGrid") as Grid;
//if (rankingGrid == null) return;
var rankingGrid = FindName("RankingGrid") as Grid;
if (rankingGrid == null) return;
rankingGrid.Visibility = Visibility.Visible;
var fadeIn = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(600));
rankingGrid.BeginAnimation(UIElement.OpacityProperty, fadeIn);
//rankingGrid.Visibility = Visibility.Visible;
//var fadeIn = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(600));
//rankingGrid.BeginAnimation(UIElement.OpacityProperty, fadeIn);
}
// 控制排行榜隐藏(渐隐动画)
public void HideRankingBoard()
/*
*
* time:
* name:
*/
public void HideElement(string name , int time)
{
var rankingGrid = FindName("RankingGrid") as Grid;
if (rankingGrid == null) return;
var Element = FindName(name) as Grid;
if (Element == null) return;
var fadeOut = new DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(600));
fadeOut.Completed += (s, e) => rankingGrid.Visibility = Visibility.Collapsed;
rankingGrid.BeginAnimation(UIElement.OpacityProperty, fadeOut);
var fadeOut = new DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(time));
fadeOut.Completed += (s, e) => Element.Visibility = Visibility.Collapsed;
Element.BeginAnimation(UIElement.OpacityProperty, fadeOut);
}
/*
*
* time:
* name:
*/
public void showElement(string name, int time = 600 )
{
var Element = FindName(name) as FrameworkElement;
if (Element == null) return;
Element.Visibility = Visibility.Visible;
var fadeIn = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(time));
Element.BeginAnimation(UIElement.OpacityProperty, fadeIn);
}
}

View File

@ -4,9 +4,24 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Wpf_AiSportsMicrospace.Views"
xmlns:gif="http://wpfanimatedgif.codeplex.com"
mc:Ignorable="d" WindowState="Maximized">
<Grid>
<!-- 过渡容器 -->
<ContentControl x:Name="MainContent"/>
<!--倒计时-->
<Grid Height="1080" Width="1920" Visibility="Hidden" x:Name="CountTimeGrid" >
<Border Background="#000" Opacity="0.3" />
<Image
gif:ImageBehavior.AnimatedSource="/Resources/Img/gif/time_3.gif"
gif:ImageBehavior.RepeatBehavior="1x"
gif:ImageBehavior.AutoStart="False"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="0,0,0,0"
x:Name="time3"
Visibility="Hidden"
/>
</Grid>
</Grid>
</Window>

View File

@ -14,6 +14,7 @@ using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using Wpf_AiSportsMicrospace.Common;
using WpfAnimatedGif;
using Yztob.AiSports.Inferences.Abstractions;
using Yztob.AiSports.Inferences.Things;
using Yztob.AiSports.Sensors.Abstractions;
@ -64,6 +65,8 @@ namespace Wpf_AiSportsMicrospace.Views
//StartHeartbeatMonitor();
// 默认显示首页
MainContent.Content = new Home();
ImageBehavior.AddAnimationCompletedHandler(time3, TimeDown);
}
private void StartFrameProcessing()
{
@ -347,5 +350,36 @@ namespace Wpf_AiSportsMicrospace.Views
maskTop.RenderTransform.BeginAnimation(TranslateTransform.YProperty, topInAnim);
maskBottom.RenderTransform.BeginAnimation(TranslateTransform.YProperty, bottomInAnim);
}
public void ShowElement(string name, int time = 600)
{
var Element = FindName(name) as FrameworkElement;
if (Element == null) return;
Element.Visibility = Visibility.Visible;
var fadeIn = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(time));
Element.BeginAnimation(UIElement.OpacityProperty, fadeIn);
}
int num = 1;
public void ShowCountDownAnimation()
{
ImageBehavior.SetRepeatBehavior(time3, new RepeatBehavior(2));
ImageBehavior.SetRepeatBehavior(time3, new RepeatBehavior(1));
CountTimeGrid.Visibility = Visibility.Visible;
time3.Visibility = Visibility.Visible;
ImageBehavior.GetAnimationController(time3).Play();
}
private void TimeDown(object? sender, RoutedEventArgs? e)
{
//MessageBox.Show("播放完啦");// 弹提示框
ImageBehavior.GetAnimationController(time3).Pause();
CountTimeGrid.Visibility = Visibility.Hidden;
time3.Visibility = Visibility.Hidden;
num++;
}
}
}

View File

@ -40,6 +40,7 @@
<None Remove="Resources\Img\gif\2.gif" />
<None Remove="Resources\Img\gif\3.gif" />
<None Remove="Resources\Img\gif\bottom_animation_image.png" />
<None Remove="Resources\Img\gif\time_3.gif" />
<None Remove="Resources\Img\gif\top_animation_image.png" />
<None Remove="Resources\Img\play_img\play_home_bg.png" />
<None Remove="Resources\Img\play_img\play_home_title.png" />
@ -208,6 +209,9 @@
<Resource Include="Resources\Img\gif\bottom_animation_image.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Resources\Img\gif\time_3.gif">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Resources\Img\gif\top_animation_image.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>