Search in sources :

Example 6 with ResultMetadataType

use of com.google.zxing.ResultMetadataType in project zxing-android-embedded by journeyapps.

the class CaptureManager method resultIntent.

/**
     * Create a intent to return as the Activity result.
     *
     * @param rawResult the BarcodeResult, must not be null.
     * @param barcodeImagePath a path to an exported file of the Barcode Image, can be null.
     * @return the Intent
     */
public static Intent resultIntent(BarcodeResult rawResult, String barcodeImagePath) {
    Intent intent = new Intent(Intents.Scan.ACTION);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.putExtra(Intents.Scan.RESULT, rawResult.toString());
    intent.putExtra(Intents.Scan.RESULT_FORMAT, rawResult.getBarcodeFormat().toString());
    byte[] rawBytes = rawResult.getRawBytes();
    if (rawBytes != null && rawBytes.length > 0) {
        intent.putExtra(Intents.Scan.RESULT_BYTES, rawBytes);
    }
    Map<ResultMetadataType, ?> metadata = rawResult.getResultMetadata();
    if (metadata != null) {
        if (metadata.containsKey(ResultMetadataType.UPC_EAN_EXTENSION)) {
            intent.putExtra(Intents.Scan.RESULT_UPC_EAN_EXTENSION, metadata.get(ResultMetadataType.UPC_EAN_EXTENSION).toString());
        }
        Number orientation = (Number) metadata.get(ResultMetadataType.ORIENTATION);
        if (orientation != null) {
            intent.putExtra(Intents.Scan.RESULT_ORIENTATION, orientation.intValue());
        }
        String ecLevel = (String) metadata.get(ResultMetadataType.ERROR_CORRECTION_LEVEL);
        if (ecLevel != null) {
            intent.putExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL, ecLevel);
        }
        @SuppressWarnings("unchecked") Iterable<byte[]> byteSegments = (Iterable<byte[]>) metadata.get(ResultMetadataType.BYTE_SEGMENTS);
        if (byteSegments != null) {
            int i = 0;
            for (byte[] byteSegment : byteSegments) {
                intent.putExtra(Intents.Scan.RESULT_BYTE_SEGMENTS_PREFIX + i, byteSegment);
                i++;
            }
        }
    }
    if (barcodeImagePath != null) {
        intent.putExtra(Intents.Scan.RESULT_BARCODE_IMAGE_PATH, barcodeImagePath);
    }
    return intent;
}
Also used : ResultMetadataType(com.google.zxing.ResultMetadataType) Intent(android.content.Intent) ResultPoint(com.google.zxing.ResultPoint)

Example 7 with ResultMetadataType

use of com.google.zxing.ResultMetadataType in project weex-example by KalicyZhou.

the class UPCEANExtension5Support method decodeRow.

Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange) throws NotFoundException {
    StringBuilder result = decodeRowStringBuffer;
    result.setLength(0);
    int end = decodeMiddle(row, extensionStartRange, result);
    String resultString = result.toString();
    Map<ResultMetadataType, Object> extensionData = parseExtensionString(resultString);
    Result extensionResult = new Result(resultString, null, new ResultPoint[] { new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, (float) rowNumber), new ResultPoint((float) end, (float) rowNumber) }, BarcodeFormat.UPC_EAN_EXTENSION);
    if (extensionData != null) {
        extensionResult.putAllMetadata(extensionData);
    }
    return extensionResult;
}
Also used : ResultPoint(com.google.zxing.ResultPoint) ResultMetadataType(com.google.zxing.ResultMetadataType) ResultPoint(com.google.zxing.ResultPoint) Result(com.google.zxing.Result)

Example 8 with ResultMetadataType

use of com.google.zxing.ResultMetadataType in project zxing by zxing.

the class MultiQRCodeTestCase method testMultiQRCodes.

@Test
public void testMultiQRCodes() throws Exception {
    // Very basic test for now
    Path testBase = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/multi-qrcode-1");
    Path testImage = testBase.resolve("1.png");
    BufferedImage image = ImageIO.read(testImage.toFile());
    LuminanceSource source = new BufferedImageLuminanceSource(image);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    MultipleBarcodeReader reader = new QRCodeMultiReader();
    Result[] results = reader.decodeMultiple(bitmap);
    assertNotNull(results);
    assertEquals(4, results.length);
    Set<String> barcodeContents = new HashSet<>();
    for (Result result : results) {
        barcodeContents.add(result.getText());
        assertEquals(BarcodeFormat.QR_CODE, result.getBarcodeFormat());
        Map<ResultMetadataType, Object> metadata = result.getResultMetadata();
        assertNotNull(metadata);
    }
    Set<String> expectedContents = new HashSet<>();
    expectedContents.add("You earned the class a 5 MINUTE DANCE PARTY!!  Awesome!  Way to go!  Let's boogie!");
    expectedContents.add("You earned the class 5 EXTRA MINUTES OF RECESS!!  Fabulous!!  Way to go!!");
    expectedContents.add("You get to SIT AT MRS. SIGMON'S DESK FOR A DAY!!  Awesome!!  Way to go!! Guess I better clean up! :)");
    expectedContents.add("You get to CREATE OUR JOURNAL PROMPT FOR THE DAY!  Yay!  Way to go!  ");
    assertEquals(expectedContents, barcodeContents);
}
Also used : Path(java.nio.file.Path) MultipleBarcodeReader(com.google.zxing.multi.MultipleBarcodeReader) HybridBinarizer(com.google.zxing.common.HybridBinarizer) BufferedImage(java.awt.image.BufferedImage) Result(com.google.zxing.Result) LuminanceSource(com.google.zxing.LuminanceSource) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) ResultMetadataType(com.google.zxing.ResultMetadataType) BinaryBitmap(com.google.zxing.BinaryBitmap) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with ResultMetadataType

use of com.google.zxing.ResultMetadataType in project zxing by zxing.

the class UPCEANExtension2Support method decodeRow.

Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange) throws NotFoundException {
    StringBuilder result = decodeRowStringBuffer;
    result.setLength(0);
    int end = decodeMiddle(row, extensionStartRange, result);
    String resultString = result.toString();
    Map<ResultMetadataType, Object> extensionData = parseExtensionString(resultString);
    Result extensionResult = new Result(resultString, null, new ResultPoint[] { new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, rowNumber), new ResultPoint(end, rowNumber) }, BarcodeFormat.UPC_EAN_EXTENSION);
    if (extensionData != null) {
        extensionResult.putAllMetadata(extensionData);
    }
    return extensionResult;
}
Also used : ResultPoint(com.google.zxing.ResultPoint) ResultMetadataType(com.google.zxing.ResultMetadataType) ResultPoint(com.google.zxing.ResultPoint) Result(com.google.zxing.Result)

Example 10 with ResultMetadataType

use of com.google.zxing.ResultMetadataType in project zxing by zxing.

the class UPCEANExtension5Support method decodeRow.

Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange) throws NotFoundException {
    StringBuilder result = decodeRowStringBuffer;
    result.setLength(0);
    int end = decodeMiddle(row, extensionStartRange, result);
    String resultString = result.toString();
    Map<ResultMetadataType, Object> extensionData = parseExtensionString(resultString);
    Result extensionResult = new Result(resultString, null, new ResultPoint[] { new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, rowNumber), new ResultPoint(end, rowNumber) }, BarcodeFormat.UPC_EAN_EXTENSION);
    if (extensionData != null) {
        extensionResult.putAllMetadata(extensionData);
    }
    return extensionResult;
}
Also used : ResultPoint(com.google.zxing.ResultPoint) ResultMetadataType(com.google.zxing.ResultMetadataType) ResultPoint(com.google.zxing.ResultPoint) Result(com.google.zxing.Result)

Aggregations

ResultMetadataType (com.google.zxing.ResultMetadataType)11 ResultPoint (com.google.zxing.ResultPoint)8 Result (com.google.zxing.Result)6 Intent (android.content.Intent)4 Paint (android.graphics.Paint)3 Map (java.util.Map)3 DateFormat (java.text.DateFormat)2 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 SurfaceView (android.view.SurfaceView)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BinaryBitmap (com.google.zxing.BinaryBitmap)1 BufferedImageLuminanceSource (com.google.zxing.BufferedImageLuminanceSource)1 DecodeHintType (com.google.zxing.DecodeHintType)1 LuminanceSource (com.google.zxing.LuminanceSource)1 ReaderException (com.google.zxing.ReaderException)1 ResultButtonListener (com.google.zxing.client.android.result.ResultButtonListener)1