Search in sources :

Example 1 with BarCodeReader

use of com.aspose.barcode.barcoderecognition.BarCodeReader in project Aspose.BarCode-for-Java by aspose-barcode.

the class MarkingBarcodeRegionsInAnImage method main.

public static void main(String[] args) throws Exception {
    ApplyALicense.applyALicense();
    // The path to the resource directory.
    String dataDir = Utils.getDataDir(MarkingBarcodeRegionsInAnImage.class) + "BarcodeReader/advanced_features/";
    // Create an instance of BarCodeReader class and specify the image and symbology
    BarCodeReader reader = new BarCodeReader(dataDir + "Code39Std.png", com.aspose.barcode.barcoderecognition.DecodeType.CODE_39_STANDARD);
    // Read all the barcodes from the images
    while (reader.read()) {
        // Display the symbology type
        System.out.println("BarCode Type: " + reader.getCodeType());
        // Display the codetext
        System.out.println("BarCode CodeText: " + reader.getCodeText());
        // Get the barcode region
        BarCodeRegion region = reader.getRegion();
        if (region != null) {
            // Initialize an object of type BufferedImage to get the Graphics object
            BufferedImage bufferedImage = ImageIO.read(new File(dataDir + "Code39Std.png"));
            // Initialize graphics object from the image
            Graphics g = bufferedImage.getGraphics();
            // Initialize paint object
            Paint p = new GradientPaint(0, 0, Color.red, 100, 100, Color.pink, true);
            region.drawBarCodeEdges(g, Color.RED);
            // Save the image
            ImageIO.write(bufferedImage, "png", new File(dataDir + "Code39StdOut.png"));
        }
    }
    reader.close();
}
Also used : Graphics(java.awt.Graphics) GradientPaint(java.awt.GradientPaint) BarCodeReader(com.aspose.barcode.barcoderecognition.BarCodeReader) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) BarCodeRegion(com.aspose.barcode.barcoderecognition.BarCodeRegion)

Example 2 with BarCodeReader

use of com.aspose.barcode.barcoderecognition.BarCodeReader in project Aspose.BarCode-for-Java by aspose-barcode.

the class LoadingFromAFile method main.

public static void main(String[] args) {
    // The path to the resource directory.
    String dataDir = Utils.getDataDir(LoadingFromAFile.class) + "BarcodeReader/loading_images/";
    // Initialize bar code reader
    BarCodeReader reader = new BarCodeReader(dataDir + "CodeText.jpg");
    // OR
    // Initialize bar code reader
    BarCodeReader barcodeReader = new BarCodeReader(dataDir + "CodeText.jpg", com.aspose.barcode.barcoderecognition.DecodeType.CODE_39_EXTENDED);
}
Also used : BarCodeReader(com.aspose.barcode.barcoderecognition.BarCodeReader)

Example 3 with BarCodeReader

use of com.aspose.barcode.barcoderecognition.BarCodeReader in project Aspose.BarCode-for-Java by aspose-barcode.

the class BarcodeRegionInformationFromTheImage method main.

public static void main(String[] args) throws Exception {
    ApplyALicense.applyALicense();
    // The path to the resource directory.
    String dataDir = Utils.getDataDir(BarcodeRegionInformationFromTheImage.class) + "BarcodeReader/advanced_features/";
    // Read code39 barcode from image
    String imageFilePath = dataDir + "code39Extended.jpg";
    BarCodeReader reader = new BarCodeReader(imageFilePath, com.aspose.barcode.barcoderecognition.DecodeType.CODE_39_STANDARD);
    // Try to recognize all possible barcodes in the image
    while (reader.read()) {
        // Get the region information
        BarCodeRegion region = reader.getRegion();
        if (region != null) {
            // Display x and y coordinates of barcode detected
            Point[] point = region.getPoints();
            System.out.println("Top left coordinates: X = " + point[0].x + ", Y = " + point[0].y);
            System.out.println("Bottom left coordinates: X = " + point[1].x + ", Y = " + point[1].y);
            System.out.println("Bottom right coordinates: X = " + point[2].x + ", Y = " + point[2].y);
            System.out.println("Top right coordinates: X = " + point[3].x + ", Y = " + point[3].y);
        }
        System.out.println("Codetext: " + reader.getCodeText());
    }
    // Close the reader
    reader.close();
}
Also used : BarCodeReader(com.aspose.barcode.barcoderecognition.BarCodeReader) Point(java.awt.Point) BarCodeRegion(com.aspose.barcode.barcoderecognition.BarCodeRegion)

Example 4 with BarCodeReader

use of com.aspose.barcode.barcoderecognition.BarCodeReader in project Aspose.BarCode-for-Java by aspose-barcode.

the class DetectTheUnicodeEncoding method main.

public static void main(String[] args) throws Exception {
    ApplyALicense.applyALicense();
    // The path to the resource directory.
    String dataDir = Utils.getDataDir(DetectTheUnicodeEncoding.class) + "2DBarcode/BasicFeatures/";
    String imageFilePath = dataDir + "unicodeEncoding.png";
    BarCodeBuilder builder = new BarCodeBuilder();
    builder.setCodeText("Слово");
    builder.setEncodeType(com.aspose.barcode.EncodeTypes.QR);
    builder.setCodeTextEncoding(StandardCharsets.UTF_8);
    builder.save(imageFilePath, BarCodeImageFormat.Png);
    BarCodeReader reader = new BarCodeReader(imageFilePath, com.aspose.barcode.barcoderecognition.DecodeType.QR);
    reader.setDetectEncoding(true);
    if (reader.read()) {
        // "Слово"
        System.out.println(reader.getCodeText());
    }
}
Also used : BarCodeBuilder(com.aspose.barcode.BarCodeBuilder) BarCodeReader(com.aspose.barcode.barcoderecognition.BarCodeReader)

Example 5 with BarCodeReader

use of com.aspose.barcode.barcoderecognition.BarCodeReader in project Aspose.BarCode-for-Java by aspose-barcode.

the class ApplyingChecksumValidation method main.

public static void main(String[] args) {
    // The path to the resource directory.
    String dataDir = Utils.getDataDir(ApplyingChecksumValidation.class) + "Barcode/AdvancedFeatures/";
    // Create an instance of BarCodeReader class and load an existing
    // oncecode barcode.
    BarCodeReader r = new BarCodeReader(dataDir + "onecode.png", DecodeType.ONE_CODE);
    // Set the ChecksumValidation property to Off.
    r.setChecksumValidation(ChecksumValidation.Off);
    while (r.read()) {
        System.out.println(r.getCodeType() + ": " + r.getCodeText());
        System.out.println("CheckSum: " + r.getCheckSum());
    }
}
Also used : BarCodeReader(com.aspose.barcode.barcoderecognition.BarCodeReader)

Aggregations

BarCodeReader (com.aspose.barcode.barcoderecognition.BarCodeReader)19 File (java.io.File)5 BufferedImage (java.awt.image.BufferedImage)4 BarCodeRegion (com.aspose.barcode.barcoderecognition.BarCodeRegion)2 Point (java.awt.Point)2 Rectangle (java.awt.Rectangle)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 BarCodeBuilder (com.aspose.barcode.BarCodeBuilder)1 GradientPaint (java.awt.GradientPaint)1 Graphics (java.awt.Graphics)1 Paint (java.awt.Paint)1 FileFilter (java.io.FileFilter)1