-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
90 lines (71 loc) · 2.54 KB
/
Form1.cs
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
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace Encoder {
public partial class Form1 : Form {
Encoder encoder;
Decoder decoder;
Bitmap bitmap;
bool busy = false;
public Form1() {
InitializeComponent();
}
private void Compress(object sender, EventArgs e) {
if (busy)
return;
OpenFileDialog fd = new OpenFileDialog();
if (fd.ShowDialog() != DialogResult.OK)
return;
bitmap = new Bitmap(fd.FileName);
encoder = new Encoder();
if (!compressionWorker.IsBusy)
compressionWorker.RunWorkerAsync();
}
private void Decompress(object sender, EventArgs e) {
decoder = new Decoder();
if (!decompressionWorker.IsBusy && !busy)
decompressionWorker.RunWorkerAsync();
}
new private void Resize(int wide, int high) {
table.RowStyles.Clear();
table.RowStyles.Add(new RowStyle(SizeType.Absolute, high));
table.RowStyles.Add(new RowStyle(SizeType.Absolute, 26F));
table.RowStyles.Add(new RowStyle(SizeType.Absolute, 26F));
Width = 2 * wide;
Height = high + 96;
Update();
}
private void DoCompressionWork(object sender, DoWorkEventArgs e) {
if (bitmap == null)
return;
busy = true;
encoder.Start(bitmap);
}
private void CompressionWorkCompleted(object sender, RunWorkerCompletedEventArgs e) {
Resize(encoder.bitmap.Width, encoder.bitmap.Height);
pic1.Image = encoder.bitmap;
busy = false;
}
private void DoDecompressionWork(object sender, DoWorkEventArgs e) {
busy = true;
decoder.Start();
}
private void DecompressionWorkCompleted(object sender, RunWorkerCompletedEventArgs e) {
Resize(decoder.bm.Width, decoder.bm.Height);
pic2.Image = decoder.bm;
busy = false;
}
private void GenerateVectors(object sender, EventArgs e) {
encoder = new Encoder();
encoder.StartVectors();
pic1.Image = encoder.bitmap;
pic1.Invalidate();
}
private void DecodeVectors(object sender, EventArgs e) {
}
}
}