Skip to content

Commit 71ac462

Browse files
committed
initial
1 parent 7dce169 commit 71ac462

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@
2121

2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
24+
25+
.idea
26+
res
27+
target

pom.xml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>isc</groupId>
8+
<artifactId>barcode</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<dependencies>
13+
<dependency>
14+
<groupId>com.google.zxing</groupId>
15+
<artifactId>core</artifactId>
16+
<version>3.4.1</version>
17+
</dependency>
18+
<dependency>
19+
<groupId>com.google.zxing</groupId>
20+
<artifactId>javase</artifactId>
21+
<version>3.4.1</version>
22+
</dependency>
23+
</dependencies>
24+
<build>
25+
<plugins>
26+
<!-- <plugin>
27+
<groupId>org.apache.maven.plugins</groupId>
28+
<artifactId>maven-dependency-plugin</artifactId>
29+
<executions>
30+
<execution>
31+
<id>copy-dependencies</id>
32+
<phase>prepare-package</phase>
33+
<goals>
34+
<goal>copy-dependencies</goal>
35+
</goals>
36+
<configuration>
37+
<outputDirectory>${project.build.directory}/lib</outputDirectory>
38+
<overWriteReleases>false</overWriteReleases>
39+
<overWriteSnapshots>false</overWriteSnapshots>
40+
<overWriteIfNewer>true</overWriteIfNewer>
41+
</configuration>
42+
</execution>
43+
</executions>
44+
</plugin>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-jar-plugin</artifactId>
48+
<configuration>
49+
<archive>
50+
<manifest>
51+
<addClasspath>true</addClasspath>
52+
<classpathPrefix>libs/</classpathPrefix>
53+
<mainClass>
54+
isc.barcode
55+
</mainClass>
56+
</manifest>
57+
</archive>
58+
</configuration>
59+
</plugin>-->
60+
<plugin>
61+
<groupId>org.apache.maven.plugins</groupId>
62+
<artifactId>maven-assembly-plugin</artifactId>
63+
<executions>
64+
<execution>
65+
<phase>package</phase>
66+
<goals>
67+
<goal>single</goal>
68+
</goals>
69+
<configuration>
70+
<archive>
71+
<manifest>
72+
<mainClass>
73+
isc.barcode
74+
</mainClass>
75+
</manifest>
76+
</archive>
77+
<descriptorRefs>
78+
<descriptorRef>jar-with-dependencies</descriptorRef>
79+
</descriptorRefs>
80+
</configuration>
81+
</execution>
82+
</executions>
83+
</plugin>
84+
</plugins>
85+
</build>
86+
</project>

src/main/java/isc/barcode.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package isc;
2+
3+
import java.io.FileInputStream;
4+
import java.io.IOException;
5+
import java.util.EnumMap;
6+
import java.util.EnumSet;
7+
import java.util.Map;
8+
import javax.imageio.ImageIO;
9+
import com.google.zxing.*;
10+
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
11+
import com.google.zxing.common.HybridBinarizer;
12+
import com.google.zxing.multi.GenericMultipleBarcodeReader;
13+
14+
15+
import static com.google.zxing.common.CharacterSetECI.UTF8;
16+
17+
public class barcode {
18+
Map<DecodeHintType, Object> hintsMap = new EnumMap<DecodeHintType, Object>(DecodeHintType.class);
19+
GenericMultipleBarcodeReader reader = new GenericMultipleBarcodeReader(new MultiFormatReader());
20+
21+
public barcode() {
22+
hintsMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
23+
hintsMap.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.of(BarcodeFormat.CODE_128));
24+
hintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.FALSE);
25+
hintsMap.put(DecodeHintType.CHARACTER_SET, UTF8);
26+
}
27+
28+
// Function to read the file with Barcode
29+
public String[] readBarCode(String path) throws IOException {
30+
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(new FileInputStream(path)))));
31+
String[] resultsText = new String[0];
32+
try {
33+
Result[] results = reader.decodeMultiple(binaryBitmap, hintsMap);
34+
resultsText = new String[results.length];
35+
for (int i = 0; i < results.length; i++) {
36+
resultsText[i] = results[i].getText();
37+
}
38+
} catch (NotFoundException ex) {
39+
}
40+
41+
return resultsText;
42+
}
43+
44+
}
45+

0 commit comments

Comments
 (0)