Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- //--< using >--
- using System.IO; //Folder, Directory
- using System.Windows.Forms;
- using System.Windows.Media.Animation;
- //--</ using >--
- namespace Work3110Animation
- {
- /// <summary>
- /// Логика взаимодействия для SlideShow.xaml
- /// </summary>
- public partial class SlideShow : Window
- {
- List<BitmapImage> bitmapImages = new List<BitmapImage>();
- Storyboard storyboard = new Storyboard();
- int i = 0;
- bool flag = false;
- public SlideShow()
- {
- InitializeComponent();
- }
- private void bt_Select_Click(object sender, RoutedEventArgs e)
- {
- FolderBrowserDialog folderDialog = new FolderBrowserDialog();
- folderDialog.ShowNewFolderButton = false;
- folderDialog.SelectedPath = AppDomain.CurrentDomain.BaseDirectory;
- DialogResult result = folderDialog.ShowDialog();
- string[] imageEx =
- {
- ".jpeg",
- ".jpg",
- ".png",
- ".bmp",
- ".jp2",
- ".jxr",
- ".gif",
- ".pic",
- ".ico",
- ".svg",
- ".avif"
- };
- if (result == System.Windows.Forms.DialogResult.OK)
- {
- DirectoryInfo folder = new DirectoryInfo(folderDialog.SelectedPath);
- if (folder.Exists)
- {
- //------< @Loop: Files >------
- foreach (var fileInfo in folder.GetFiles())
- {
- if (imageEx.Contains(fileInfo.Extension))
- bitmapImages.Add(new BitmapImage(new Uri(fileInfo.FullName, UriKind.Absolute)));
- }
- }
- }
- i = 0;
- im1.Source = bitmapImages[i];
- Curr_im.Content = $"{i + 1}/{bitmapImages.Count}";
- InitAnimimation();
- }
- private void show_Click(object sender, RoutedEventArgs e)
- {
- }
- private void bt_StopAnimation_Click(object sender, RoutedEventArgs e)
- {
- storyboard.Pause();
- }
- private void bt_Prev_Click(object sender, RoutedEventArgs e)
- {
- i--;
- if (i == -1) i = bitmapImages.Count-1;
- storyboard.Seek(TimeSpan.FromSeconds(i+1));
- im1.Source = bitmapImages[i];
- Curr_im.Content = $"{i+1}/{bitmapImages.Count}";
- }
- private void InitAnimimation()
- {
- var animation = new ObjectAnimationUsingKeyFrames();
- Storyboard.SetTarget(animation, im1);
- Storyboard.SetTargetProperty(animation, new PropertyPath("Source"));
- TimeSpan currentInteval = TimeSpan.FromMilliseconds(1);
- foreach (var imageName in bitmapImages)
- {
- ObjectKeyFrame keyFrame = new DiscreteObjectKeyFrame();
- keyFrame.Value = imageName;
- keyFrame.KeyTime = currentInteval;
- animation.KeyFrames.Add(keyFrame);
- currentInteval = currentInteval.Add(TimeSpan.FromSeconds(1));
- }
- storyboard.RepeatBehavior = RepeatBehavior.Forever;
- storyboard.Children.Add(animation);
- storyboard.Begin();
- storyboard.Pause();
- }
- private void bt_StartAnimation_Click(object sender, RoutedEventArgs e)
- {
- storyboard.Resume();
- Curr_im.Content = $"{storyboard.GetCurrentTime().Seconds}/{bitmapImages.Count}";
- }
- private void bt_next_Click(object sender, RoutedEventArgs e)
- {
- i++;
- if (i == bitmapImages.Count) i = 0;
- storyboard.Seek(TimeSpan.FromSeconds(i+1));
- im1.Source = bitmapImages[i];
- Curr_im.Content = $"{i + 1}/{bitmapImages.Count}";
- }
- private void Curr_im_TextInput(object sender, TextCompositionEventArgs e)
- {
- }
- private void Curr_im_TargetUpdated(object sender, DataTransferEventArgs e)
- {
- }
- private void Curr_im_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- System.Windows.MessageBox.Show("A1kkkk");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement