-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMaximize.cs
More file actions
95 lines (86 loc) · 2.37 KB
/
Copy pathMaximize.cs
File metadata and controls
95 lines (86 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using Emgu.CV.Flann;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace Codeformer_Dotnet
{
public partial class Maximize : Form
{
string _path;
double _fps;
int _index;
bool isPlaying = false;
int _frameCount = 0;
public Maximize(string path, double fps, int index, int frameCount)
{
_path = path;
_fps = fps;
_index = index;
_frameCount = frameCount;
InitializeComponent();
}
private void Maximize_Load(object sender, EventArgs e)
{
LoadImage(GetInputImageWithIndex(_index));
}
private async void pictureBox1_Click(object sender, EventArgs e)
{
await PlayVideo();
}
private async Task PlayVideo()
{
await Task.Run(() => {
isPlaying = !isPlaying;
while (true)
{
Thread.Sleep(Convert.ToInt32(_fps));
if (!isPlaying)
{
break;
}
if (!File.Exists(GetInputImageWithIndex(_index)))
{
_index = 1;
}
else
{
LoadImage(GetInputImageWithIndex(_index));
}
if (_index < _frameCount)
{
_index++;
}
else
{
_index = 1;
}
}
});
}
private void LoadImage(string src)
{
if (pictureBox1.InvokeRequired)
{
BeginInvoke(new Action(() =>
{
pictureBox1.ImageLocation = src;
}));
}
else
{
pictureBox1.ImageLocation = src;
}
}
private string GetInputImageWithIndex(int index)
{
return $"{_path}/frame_{index:00000000}.png";
}
}
}