| |
 |
Read Linear, 2D and Postal Barcodes - Specify Advanced Options |
 |
This demo reads the image and recognizes the barcode from it.
You can freely upload your image to our website and scan for barcodes.
Different symbology types are available to choose from. You can check all or any specific symbology.
Popular image formats like bmp, jpeg, jpg, gif, png etc may be uploaded in this demo.
You may specify the advance options like scan strength and image binarizations for the barcode recognition.
For more details please see the following topics:
| ASP.NET |
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
|
<%@ page language="C#" masterpagefile="~/tpl/Demo.Master" autoeventwireup="true" inherits="NewOnline.Recognition, App_Web_7hegysqt" title="Read Linear, 2D and Postal Barcodes - Specify Advanced Options" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<table width="90%" align="center" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="19"><img src="/Common/images/heading_lft.jpg" alt="" width="19" height="41" /></td>
<td width="100%" class="demos-heading-bg"><h2 class="demos-heading-bg" style="text-align: left"> Read Linear, 2D and Postal Barcodes - Specify Advanced Options</h2></td>
<td width="19"><img src="/Common/images/heading_rt.jpg" alt="" width="19" height="41" /></td>
</tr>
</table>
<br />
<p class="componentDescriptionTxt" style="text-align: left">
This demo reads the image and recognizes the barcode from it.
You can freely upload your image to our website and scan for barcodes.
Different symbology types are available to choose from. You can check all or any specific symbology.
Popular image formats like bmp, jpeg, jpg, gif, png etc may be uploaded in this demo.
You may specify the advance options like scan strength and image binarizations for the barcode recognition.
<br><br>For more details please see the following topics:
</p>
<ul>
<li style="text-align: left">
<a href="http://www.aspose.com/documentation/.net-components/aspose.barcode-for-.net/introducing-barcode-recognition.html">BarCode Recognition with Aspose.BarCode</a>
</li>
<li style="text-align: left">
<a href="http://www.aspose.com/documentation/.net-components/aspose.barcode-for-.net/scan-result.html">Getting the Result After BarCode Recognition</a>
</li>
<li style="text-align: left">
<a href="http://www.aspose.com/documentation/.net-components/aspose.barcode-for-.net/better-and-faster-image-processing-for-barcode-recognition.html">Better and Faster Image Processing for BarCode Recognition</a>
</li>
<li style="text-align: left">
<a href="http://www.aspose.com/documentation/.net-components/aspose.barcode-for-.net/controlling-the-scan-strength-during-the-barcode-recognition-process.html">Controlling the Scan Strength during the Barcode Recognition Process</a>
</li>
</ul>
<table class="genericTable">
<tr>
<td style="text-align: left"><table>
<tr>
<td align="left">
Choose the symbologies
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="text-align: left">
<asp:Button ID="Button3" runat="server" Text="Select All Symbologies"
onclick="Button3_Click" />
<asp:Button ID="Button4" runat="server" Text="Select None"
onclick="Button4_Click" />
</td>
</tr>
<tr>
<td style="text-align: left">
<asp:CheckBoxList ID="chSymbology" runat="server" CellPadding="3"
CellSpacing="3" RepeatColumns="5" RepeatDirection="Horizontal">
</asp:CheckBoxList>
</td>
</tr>
<tr>
<td style="text-align: left">
<table>
<tr>
<td>
Image Binarization</td>
<td>
<asp:CheckBoxList ID="chImageBinarization" runat="server" CellPadding="3"
CellSpacing="3" RepeatDirection="Horizontal">
</asp:CheckBoxList>
</td>
</tr>
<tr>
<td>
Orientation</td>
<td>
<asp:CheckBoxList ID="chOrientation" runat="server" CellPadding="3"
CellSpacing="3" RepeatDirection="Horizontal">
</asp:CheckBoxList>
</td>
</tr>
<tr>
<td>
Scan Strength</td>
<td>
<asp:CheckBoxList ID="chScanStrength" runat="server" CellPadding="3"
CellSpacing="3" RepeatDirection="Horizontal">
</asp:CheckBoxList>
</td>
</tr>
<tr>
<td>
Threshold</td>
<td>
<asp:CheckBoxList ID="chThreshold" runat="server" CellPadding="3"
CellSpacing="3" RepeatDirection="Horizontal">
</asp:CheckBoxList>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="text-align: left">
Upload image files to scan for barcodes. Please upload a file of size less than
1 MB</td>
</tr>
<tr>
<td style="text-align: left">
<input id="file1" runat="server" name="file1" size="34" style="width: 320px; height: 22px"
type="file" />
<asp:Button ID="Button1" runat="server" Height="22px" OnClick="Button1_Click" Text="Upload"
Width="80px" />
<asp:Button ID="Button2" runat="server" Height="22px" OnClick="Button2_Click" Text="Scan image"
Width="120px" /></td>
</tr>
<tr>
<td style="text-align: left">
<asp:Label
ID="Label1" runat="server" Font-Bold="True" Font-Names="Verdana" ForeColor="DarkGreen">Ready.</asp:Label>
<br />
<asp:Image ID="Image1" runat="server" ImageUrl="http://www.aspose.com/products/aspose.barcode/images/recognition/logo.jpg" />
<br />
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td style="text-align: left">
</td>
</tr>
</table>
</asp:Content>
|
| C# |
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.IO;
using Aspose.BarCodeRecognition;
namespace NewOnline
{
public partial class Recognition : System.Web.UI.Page
{
public string userImageUrl = "";
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
ArrayList arrSymbologies = Utility.GetBarcodeReadTypes();
chSymbology.DataSource = arrSymbologies;
chSymbology.DataBind();
ArrayList arrImageBinarizations = Utility.GetImageBinarizationHints();
chImageBinarization.DataSource = arrImageBinarizations;
chImageBinarization.DataBind();
ArrayList arrOrientationHints = Utility.GetOrientationHints();
chOrientation.DataSource = arrOrientationHints;
chOrientation.DataBind();
ArrayList arrScanStrengthHints = Utility.GetScanStrengthHints();
chScanStrength.DataSource = arrScanStrengthHints;
chScanStrength.DataBind();
ArrayList arrThresholdHings = Utility.GetThresholdHints();
chThreshold.DataSource = arrThresholdHings;
chThreshold.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.file1.PostedFile != null)
{
HttpPostedFile postedFile = this.file1.PostedFile;
int contentLength = postedFile.ContentLength;
if (contentLength > 1024*1024)
{
this.Label1.Text = "Error: Please upload a file of size less than 1 MB";
this.Label1.ForeColor = Color.Red;
}
else if (contentLength > 0)
{
byte[] buffer = new byte[contentLength];
postedFile.InputStream.Read(buffer, 0, contentLength);
base.Session["userfilename"] = "../userpic/" + Guid.NewGuid().ToString() + postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.'));
string path = (string)base.Session["userfilename"];
FileStream stream = new FileStream(base.Server.MapPath(path), FileMode.Create);
stream.Write(buffer, 0, buffer.Length);
stream.Close();
this.Image1.ImageUrl = path;
this.Image1.ToolTip = "this is a picture uploaded by user";
this.Label1.Text = "picture upload complete.";
this.Label1.ForeColor = Color.DarkGreen;
}
else
{
this.Label1.Text = "File length is zero";
this.Label1.ForeColor = Color.Red;
}
}
else
{
this.Label1.Text = "Please select an image file to upload";
this.Label1.ForeColor = Color.Red;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
if (base.Session["userfilename"] != null)
{
string str = base.Session["userfilename"] as string;
str = str.Remove(0, 2);
this.userImageUrl = "http://www.aspose.com/products/aspose.barcode" + str;
try
{
BarCodeReadType readType = BarCodeReadType.Empty;
RecognitionHints recognitionHints = RecognitionHints.None;
// set barcode symbologies
foreach (ListItem item in chSymbology.Items)
{
if (item.Selected == true)
{
readType |= BarCodeReadType.FromString(item.Value);
}
}
// set image binarizations
foreach (ListItem item in chImageBinarization.Items)
{
if (item.Selected == true)
{
switch(item.Value)
{
case "FixedEnlarge":
recognitionHints |= RecognitionHints.ImageBinarizationHints.FixedEnlarge;
break;
case "Grayscale":
recognitionHints |= RecognitionHints.ImageBinarizationHints.Grayscale;
break;
case "HLS":
recognitionHints |= RecognitionHints.ImageBinarizationHints.HLS;
break;
case "MedianSmoothing":
recognitionHints |= RecognitionHints.ImageBinarizationHints.MedianSmoothing;
break;
}
}
}
// set orientation hints
foreach (ListItem item in chOrientation.Items)
{
if (item.Selected == true)
{
switch (item.Value)
{
case "DownToTop":
recognitionHints |= RecognitionHints.OrientationHints.DownToTop;
break;
case "LeftToRight":
recognitionHints |= RecognitionHints.OrientationHints.LeftToRight;
break;
case "RightToLeft":
recognitionHints |= RecognitionHints.OrientationHints.RightToLeft;
break;
case "TopToDown":
recognitionHints |= RecognitionHints.OrientationHints.TopToDown;
break;
}
}
}
// set scan strength hints
foreach (ListItem item in chScanStrength.Items)
{
if (item.Selected == true)
{
switch (item.Value)
{
case "Median":
recognitionHints |= RecognitionHints.ScanStrengthHints.Median;
break;
case "Strong":
recognitionHints |= RecognitionHints.ScanStrengthHints.Strong;
break;
case "Weak":
recognitionHints |= RecognitionHints.ScanStrengthHints.Weak;
break;
}
}
}
// set threshold hints
foreach (ListItem item in chThreshold.Items)
{
if (item.Selected == true)
{
switch (item.Value)
{
case "AutoCalculateByImage":
recognitionHints |= RecognitionHints.ThresholdHints.AutoCalculateByImage;
break;
case "AutoCalculateByLine":
recognitionHints |= RecognitionHints.ThresholdHints.AutoCalculateByLine;
break;
case "FixedValues":
recognitionHints |= RecognitionHints.ThresholdHints.FixedValues;
break;
}
}
}
BarCodeReader reader = new BarCodeReader(base.Server.MapPath((string)base.Session["userfilename"]), readType);
reader.SetHints(recognitionHints);
bool bRecognized = false;
this.Label1.Text = "";
while (reader.Read() == true)
{
this.Label1.Text += "CodeText: " + reader.GetCodeText() +
"<br> BarCode Symbology: " + reader.GetReadType().ToString() + "<br><hr/>";
bRecognized = true;
}
if (bRecognized == false)
{
this.Label1.Text = "Barcode not found, please try different symbologies";
}
}
catch (Exception exception)
{
this.Label1.Text = exception.Message;
this.Label1.ForeColor = Color.Red;
}
}
else
{
this.Label1.Text = "image not found";
this.Label1.ForeColor = Color.Red;
}
}
protected void Button3_Click(object sender, EventArgs e)
{
// check all symbologies
foreach (ListItem item in chSymbology.Items)
{
item.Selected = true;
}
}
protected void Button4_Click(object sender, EventArgs e)
{
// un-check all symbologies
foreach (ListItem item in chSymbology.Items)
{
item.Selected = false;
}
}
}
}
|
|
|
|