-
Notifications
You must be signed in to change notification settings - Fork 0
/
EncoderModel.cs
112 lines (100 loc) · 2.93 KB
/
EncoderModel.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System.ComponentModel;
using System.Drawing;
namespace ImageTextEncoder
{
public class EncoderModel : INotifyPropertyChanged
{
public EncoderModel()
{
PixelsPerByte = 32;
Text = string.Empty;
Image = new Bitmap(1,1);
}
private string _text;
private Bitmap _image;
private int _pixelsPerByte;
private string _password;
public string Text
{
get { return _text; }
set
{
if (_text == value)
return;
_text = value;
OnPropertyChanged("Text");
}
}
public Bitmap Image
{
get { return _image; }
set
{
if (_image == value)
return;
_image = value;
OnPropertyChanged("Image");
OnPropertyChanged("MaxLength");
}
}
public int MaxLength
{
get
{
return _image == null
? int.MaxValue
: (_image.Width*_image.Height/PixelsPerByte) > int.MaxValue
? int.MaxValue
: (_image.Width*_image.Height/PixelsPerByte);
}
set
{}
}
public int PixelsPerByte
{
get { return _pixelsPerByte; }
set
{
if (_pixelsPerByte == value)
return;
_pixelsPerByte = value;
OnPropertyChanged("PixelsPerByte");
}
}
public string Password
{
get { return _password; }
set
{
if (_password == value)
return;
_password = value;
OnPropertyChanged("Password");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
public void Encode()
{
TextEncoderDecoder.Encode(Image, Text, PixelsPerByte);
OnPropertyChanged("Image");
}
public void Decode()
{
Text = TextEncoderDecoder.Decode(Image, PixelsPerByte);
}
public void Encrypt()
{
TextEncoderDecoder.Encode(Image, TextEncryptorDecryptor.EncryptStringAES(Text, Password), PixelsPerByte);
OnPropertyChanged("Image");
}
public void Decrypt()
{
Text = TextEncryptorDecryptor.DecryptStringAES(TextEncoderDecoder.Decode(Image, PixelsPerByte), Password);
}
}
}