-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcb.cs
174 lines (144 loc) · 4.73 KB
/
cb.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZXing.Common;
using ZXing;
using ZXing.QrCode;
using System.Drawing.Imaging;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
namespace MundoMusical.CODE_BAR
{
public class cb
{
private BarcodeWriter writer;
private Bitmap result;
private MemoryStream ms;
private FileStream stream;
private IBarcodeReader reader;
private Result Sres;
private BarcodeFormat formato = BarcodeFormat.CODE_39;
public cb()
{
this.writer = new BarcodeWriter();
this.reader = new BarcodeReader();
this.writer.Format = this.formato;
this.writer.Options.Height = 150;
this.writer.Options.Width = 160;
this.result = null;
this.ms = null;
this.stream = null;
this.Sres = null;
}
public Bitmap getImage(string val)
{
this.result = null;
try
{
this.result = new Bitmap(writer.Write(val));
}
catch (Exception ex)
{
genericDefinitions.error(ex.ToString(), "Error");
}
return this.result;
}
public Bitmap getImage(string val, int width, int height, bool includestring)
{
if (!includestring)
{
this.writer.Options.PureBarcode = true;
}
else
{
this.writer.Options.PureBarcode = false;
}
this.result = null;
this.writer.Options.Width = width;
this.writer.Options.Height = height;
try
{
this.result = new Bitmap(writer.Write(val));
}
catch (Exception ex)
{
genericDefinitions.error(ex.ToString(), "Error");
}
return this.result;
}
public Bitmap getonlycodabar(string number, int width, int height)
{
this.writer = new BarcodeWriter()
{
Options = new EncodingOptions
{
PureBarcode = true,
Height = height,
Width = width,
Margin = 0
},
Format = this.formato
};
return this.getImage(number);
}
public bool saveImage(Bitmap act, string title, string path)
{
bool flag = false;
try
{
act.RotateFlip(RotateFlipType.Rotate90FlipXY);
this.ms = new MemoryStream();
act.Save(ms, ImageFormat.Jpeg);
ms.Seek(0, SeekOrigin.Begin);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
this.stream = new FileStream(path +"\\"+title+".jpeg", FileMode.Create, FileAccess.Write);
ms.WriteTo(stream);
this.ms.Dispose();
this.stream.Dispose();
flag = true;
}
catch (Exception ex)
{
genericDefinitions.error(ex.ToString(), "Error");
}
return flag;
}
public Bitmap codeB(string value)
{
this.result = null;
try
{
this.result= new Bitmap(writer.Write(value));
this.ms = new MemoryStream();
result.Save(ms, ImageFormat.Jpeg);
ms.Seek(0, SeekOrigin.Begin);
genericDefinitions.ok(Application.StartupPath,"");
Directory.CreateDirectory(Application.StartupPath + "\\CODEBARS");
this.stream = new FileStream(Application.StartupPath+"\\CODEBARS\\"+value+ ".jpeg", FileMode.Create, FileAccess.Write);
ms.WriteTo(stream);
}
catch (Exception ex)
{
genericDefinitions.error(ex.ToString(),"Error");
}
return this.result;
}
public string decodeB(ref Bitmap bm)
{
try
{
this.Sres = reader.Decode(bm);
}catch(Exception ex)
{
genericDefinitions.error(ex.ToString(), "Error");
}
return this.Sres.ToString();
}
}
}