-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDigits.cs
120 lines (113 loc) · 2.73 KB
/
Digits.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
113
114
115
116
117
118
119
120
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
class Digits
{
private sbyte _value;
private string _binaryvalue;
private int _bitmapwidth, _bitmapheight;
private Bitmap _bitmapvalue;
protected Digits(sbyte val, int bitmapwidth, int bitmapheight)
{
_value = val;
_bitmapwidth = bitmapwidth;
_bitmapheight = bitmapheight;
}
protected static Dictionary<sbyte, string> LBinaryDigit = new Dictionary<sbyte, string>
{
{ 0, "0001101" },
{ 1, "0011001" },
{ 2, "0010011" },
{ 3, "0111101" },
{ 4, "0100011" },
{ 5, "0110001" },
{ 6, "0101111" },
{ 7, "0111011" },
{ 8, "0110111" },
{ 9, "0001011" }
};
protected static Dictionary<sbyte, string> RBinaryDigit = new Dictionary<sbyte, string>
{
{ 0, "1110010" },
{ 1, "1100110" },
{ 2, "1101100" },
{ 3, "1000010" },
{ 4, "1011100" },
{ 5, "1001110" },
{ 6, "1010000" },
{ 7, "1000100" },
{ 8, "1001000" },
{ 9, "1110100" }
};
protected static Dictionary<sbyte, string> GBinaryDigit = new Dictionary<sbyte, string>
{
{ 0, "0100111" },
{ 1, "0110011" },
{ 2, "0011011" },
{ 3, "0100001" },
{ 4, "0011101" },
{ 5, "0111001" },
{ 6, "0000101" },
{ 7, "0010001" },
{ 8, "0001001" },
{ 9, "0010111" }
};
public sbyte GetValue()
{
return _value;
}
public string GetBinaryValue()
{
return _binaryvalue;
}
protected void SetBinaryValue(char digitType)
{
if (digitType.Equals('L'))
{
LBinaryDigit.TryGetValue(_value, out _binaryvalue);
}
if (digitType.Equals('R'))
{
RBinaryDigit.TryGetValue(_value, out _binaryvalue);
}
if (digitType.Equals('G'))
{
GBinaryDigit.TryGetValue(_value, out _binaryvalue);
}
}
public int GetBitmapWidth()
{
return _bitmapwidth;
}
public void SetBitmapWidth(int bitmapwidth)
{
_bitmapwidth = bitmapwidth;
CreateBitmap(_bitmapwidth, _bitmapheight);
}
public void SetBitmapHeight(int bitmapheight)
{
_bitmapheight = bitmapheight;
CreateBitmap(_bitmapwidth, _bitmapheight);
}
public Bitmap GetBitmapValue()
{
return _bitmapvalue;
}
protected void CreateBitmap (int width, int height)
{
_bitmapvalue = new Bitmap(width, height);
Graphics gr = Graphics.FromImage(_bitmapvalue);
for (int i = 0; i <= _binaryvalue.Length - 1; i++)
{
if (_binaryvalue[i].ToString().Equals("1"))
{
gr.FillRectangle(Brushes.Black, (width / 7) * i, 0, width / 7, height);
}
else
{
gr.FillRectangle(Brushes.Transparent, (width / 7) * i, 0, width / 7, height);
}
}
}
}