-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>isc</groupId> | ||
<artifactId>barcode</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.zxing</groupId> | ||
<artifactId>core</artifactId> | ||
<version>3.4.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.zxing</groupId> | ||
<artifactId>javase</artifactId> | ||
<version>3.4.1</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<!-- <plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>copy-dependencies</id> | ||
<phase>prepare-package</phase> | ||
<goals> | ||
<goal>copy-dependencies</goal> | ||
</goals> | ||
<configuration> | ||
<outputDirectory>${project.build.directory}/lib</outputDirectory> | ||
<overWriteReleases>false</overWriteReleases> | ||
<overWriteSnapshots>false</overWriteSnapshots> | ||
<overWriteIfNewer>true</overWriteIfNewer> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addClasspath>true</addClasspath> | ||
<classpathPrefix>libs/</classpathPrefix> | ||
<mainClass> | ||
isc.barcode | ||
</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin>--> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass> | ||
isc.barcode | ||
</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package isc; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.EnumMap; | ||
import java.util.EnumSet; | ||
import java.util.Map; | ||
import javax.imageio.ImageIO; | ||
import com.google.zxing.*; | ||
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; | ||
import com.google.zxing.common.HybridBinarizer; | ||
import com.google.zxing.multi.GenericMultipleBarcodeReader; | ||
|
||
|
||
import static com.google.zxing.common.CharacterSetECI.UTF8; | ||
|
||
public class barcode { | ||
Map<DecodeHintType, Object> hintsMap = new EnumMap<DecodeHintType, Object>(DecodeHintType.class); | ||
GenericMultipleBarcodeReader reader = new GenericMultipleBarcodeReader(new MultiFormatReader()); | ||
|
||
public barcode() { | ||
hintsMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); | ||
hintsMap.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.of(BarcodeFormat.CODE_128)); | ||
hintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.FALSE); | ||
hintsMap.put(DecodeHintType.CHARACTER_SET, UTF8); | ||
} | ||
|
||
// Function to read the file with Barcode | ||
public String[] readBarCode(String path) throws IOException { | ||
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(new FileInputStream(path))))); | ||
String[] resultsText = new String[0]; | ||
try { | ||
Result[] results = reader.decodeMultiple(binaryBitmap, hintsMap); | ||
resultsText = new String[results.length]; | ||
for (int i = 0; i < results.length; i++) { | ||
resultsText[i] = results[i].getText(); | ||
} | ||
} catch (NotFoundException ex) { | ||
} | ||
|
||
return resultsText; | ||
} | ||
|
||
} | ||
|