Java Code Examples for com.google.zxing.BarcodeFormat#EAN_13
The following examples show how to use
com.google.zxing.BarcodeFormat#EAN_13 .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProductResultParser.java From barcodescanner-lib-aar with MIT License | 6 votes |
@Override public ProductParsedResult parse(Result result) { BarcodeFormat format = result.getBarcodeFormat(); if (!(format == BarcodeFormat.UPC_A || format == BarcodeFormat.UPC_E || format == BarcodeFormat.EAN_8 || format == BarcodeFormat.EAN_13)) { return null; } String rawText = getMassagedText(result); if (!isStringOfDigits(rawText, rawText.length())) { return null; } // Not actually checking the checksum again here String normalizedProductID; // Expand UPC-E for purposes of searching if (format == BarcodeFormat.UPC_E && rawText.length() == 8) { normalizedProductID = UPCEReader.convertUPCEtoUPCA(rawText); } else { normalizedProductID = rawText; } return new ProductParsedResult(rawText, normalizedProductID); }
Example 2
Source File: ProductResultParser.java From weex with Apache License 2.0 | 6 votes |
@Override public ProductParsedResult parse(Result result) { BarcodeFormat format = result.getBarcodeFormat(); if (!(format == BarcodeFormat.UPC_A || format == BarcodeFormat.UPC_E || format == BarcodeFormat.EAN_8 || format == BarcodeFormat.EAN_13)) { return null; } String rawText = getMassagedText(result); if (!isStringOfDigits(rawText, rawText.length())) { return null; } // Not actually checking the checksum again here String normalizedProductID; // Expand UPC-E for purposes of searching if (format == BarcodeFormat.UPC_E && rawText.length() == 8) { normalizedProductID = UPCEReader.convertUPCEtoUPCA(rawText); } else { normalizedProductID = rawText; } return new ProductParsedResult(rawText, normalizedProductID); }
Example 3
Source File: CaptureActivity.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
/** * Superimpose a line for 1D or dots for 2D to highlight the key features of the barcode. * * @param barcode A bitmap of the captured image. * @param scaleFactor amount by which thumbnail was scaled * @param rawResult The decoded results which contains the points to draw. */ private void drawResultPoints(Bitmap barcode, float scaleFactor, Result rawResult) { ResultPoint[] points = rawResult.getResultPoints(); if (points != null && points.length > 0) { Canvas canvas = new Canvas(barcode); Paint paint = new Paint(); paint.setColor(getResources().getColor(R.color.result_points)); if (points.length == 2) { paint.setStrokeWidth(4.0f); drawLine(canvas, paint, points[0], points[1], scaleFactor); } else if (points.length == 4 && (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A || rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) { // Hacky special case -- draw two lines, for the barcode and metadata drawLine(canvas, paint, points[0], points[1], scaleFactor); drawLine(canvas, paint, points[2], points[3], scaleFactor); } else { paint.setStrokeWidth(10.0f); for (ResultPoint point : points) { if (point != null) { canvas.drawPoint(scaleFactor * point.getX(), scaleFactor * point.getY(), paint); } } } } }
Example 4
Source File: ProductResultParser.java From RipplePower with Apache License 2.0 | 6 votes |
@Override public ProductParsedResult parse(Result result) { BarcodeFormat format = result.getBarcodeFormat(); if (!(format == BarcodeFormat.UPC_A || format == BarcodeFormat.UPC_E || format == BarcodeFormat.EAN_8 || format == BarcodeFormat.EAN_13)) { return null; } String rawText = getMassagedText(result); if (!isStringOfDigits(rawText, rawText.length())) { return null; } // Not actually checking the checksum again here String normalizedProductID; // Expand UPC-E for purposes of searching if (format == BarcodeFormat.UPC_E && rawText.length() == 8) { normalizedProductID = UPCEReader.convertUPCEtoUPCA(rawText); } else { normalizedProductID = rawText; } return new ProductParsedResult(rawText, normalizedProductID); }
Example 5
Source File: ISBNResultParser.java From RipplePower with Apache License 2.0 | 6 votes |
/** * See <a href="http://www.bisg.org/isbn-13/for.dummies.html">ISBN-13 For * Dummies</a> */ @Override public ISBNParsedResult parse(Result result) { BarcodeFormat format = result.getBarcodeFormat(); if (format != BarcodeFormat.EAN_13) { return null; } String rawText = getMassagedText(result); int length = rawText.length(); if (length != 13) { return null; } if (!rawText.startsWith("978") && !rawText.startsWith("979")) { return null; } return new ISBNParsedResult(rawText); }
Example 6
Source File: ZXingDecoder.java From react-native-barcode with MIT License | 5 votes |
private static BarcodeFormat formatToSymbol(int format) { if (225 == format) { return BarcodeFormat.AZTEC; } else if (38 == format) { return BarcodeFormat.CODABAR; } else if (128 == format) { return BarcodeFormat.CODE_128; } else if (39 == format) { return BarcodeFormat.CODE_39; } else if (93 == format) { return BarcodeFormat.CODE_93; } else if (200 == format) { return BarcodeFormat.DATA_MATRIX; } else if (13 == format) { return BarcodeFormat.EAN_13; } else if (8 == format) { return BarcodeFormat.EAN_8; } else if (25 == format) { return BarcodeFormat.ITF; } else if (94 == format) { return BarcodeFormat.MAXICODE; } else if (57 == format) { return BarcodeFormat.PDF_417; } else if (64 == format) { return BarcodeFormat.QR_CODE; } else if (34 == format) { return BarcodeFormat.RSS_14; } else if (35 == format) { return BarcodeFormat.RSS_EXPANDED; } else if (12 == format) { return BarcodeFormat.UPC_A; } else if (9 == format) { return BarcodeFormat.UPC_E; } else if (15 == format) { return BarcodeFormat.UPC_EAN_EXTENSION; } return null; }
Example 7
Source File: EAN13Writer.java From ZXing-Orient with Apache License 2.0 | 5 votes |
@Override public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType,?> hints) throws WriterException { if (format != BarcodeFormat.EAN_13) { throw new IllegalArgumentException("Can only encode EAN_13, but got " + format); } return super.encode(contents, format, width, height, hints); }
Example 8
Source File: EAN13Writer.java From QrCodeScanner with GNU General Public License v3.0 | 5 votes |
@Override public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType,?> hints) throws WriterException { if (format != BarcodeFormat.EAN_13) { throw new IllegalArgumentException("Can only encode EAN_13, but got " + format); } return super.encode(contents, format, width, height, hints); }
Example 9
Source File: EAN13Writer.java From Tesseract-OCR-Scanner with Apache License 2.0 | 5 votes |
@Override public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType,?> hints) throws WriterException { if (format != BarcodeFormat.EAN_13) { throw new IllegalArgumentException("Can only encode EAN_13, but got " + format); } return super.encode(contents, format, width, height, hints); }
Example 10
Source File: GeneralHandler.java From SecScanQR with GNU General Public License v3.0 | 5 votes |
/** * Method is used to convert parsed String to BarcodeFormat to create an image of the qr code * @param stringFormat as String * @return format as BarcodeFormat */ public BarcodeFormat StringToBarcodeFormat(String stringFormat){ BarcodeFormat format; switch(stringFormat){ case "CODBAR": format = BarcodeFormat.CODABAR; break; case "CODE_128": format= BarcodeFormat.CODE_128; break; case "CODE_39": format = BarcodeFormat.CODE_39; break; case "EAN_13": format = BarcodeFormat.EAN_13; break; case "EAN_8": format = BarcodeFormat.EAN_8; break; case "ITF": format = BarcodeFormat.ITF; break; case "PDF_417": format = BarcodeFormat.PDF_417; break; case "UPC_A": format = BarcodeFormat.UPC_A; break; case "QR_CODE": format = BarcodeFormat.QR_CODE; break; case "AZTEC": format = BarcodeFormat.AZTEC; break; default: format = BarcodeFormat.CODABAR; break; } return format; }
Example 11
Source File: BarcodeResult.java From Viewer with Apache License 2.0 | 5 votes |
/** * @param color Color of result points * @return {@link Bitmap} with result points on it, or plain bitmap, if no result points */ public Bitmap getBitmapWithResultPoints(int color) { Bitmap bitmap = getBitmap(); Bitmap barcode = bitmap; ResultPoint[] points = mResult.getResultPoints(); if (points != null && points.length > 0 && bitmap != null) { barcode = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(barcode); canvas.drawBitmap(bitmap, 0, 0, null); Paint paint = new Paint(); paint.setColor(color); if (points.length == 2) { paint.setStrokeWidth(PREVIEW_LINE_WIDTH); drawLine(canvas, paint, points[0], points[1], mScaleFactor); } else if (points.length == 4 && (mResult.getBarcodeFormat() == BarcodeFormat.UPC_A || mResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) { // Hacky special case -- draw two lines, for the barcode and metadata drawLine(canvas, paint, points[0], points[1], mScaleFactor); drawLine(canvas, paint, points[2], points[3], mScaleFactor); } else { paint.setStrokeWidth(PREVIEW_DOT_WIDTH); for (ResultPoint point : points) { if (point != null) { canvas.drawPoint(point.getX() / mScaleFactor, point.getY() / mScaleFactor, paint); } } } } return barcode; }
Example 12
Source File: EAN13Writer.java From reacteu-app with MIT License | 5 votes |
@Override public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType,?> hints) throws WriterException { if (format != BarcodeFormat.EAN_13) { throw new IllegalArgumentException("Can only encode EAN_13, but got " + format); } return super.encode(contents, format, width, height, hints); }
Example 13
Source File: ZXingDecoder.java From react-native-barcode with MIT License | 5 votes |
private static int symbolToFormat(BarcodeFormat symbol) { if (BarcodeFormat.AZTEC == symbol) { return 225; } else if (BarcodeFormat.CODABAR == symbol) { return 38; } else if (BarcodeFormat.CODE_128 == symbol) { return 128; } else if (BarcodeFormat.CODE_39 == symbol) { return 39; } else if (BarcodeFormat.CODE_93 == symbol) { return 93; } else if (BarcodeFormat.DATA_MATRIX == symbol) { return 200; } else if (BarcodeFormat.EAN_13 == symbol) { return 13; } else if (BarcodeFormat.EAN_8 == symbol) { return 8; } else if (BarcodeFormat.ITF == symbol) { return 25; } else if (BarcodeFormat.MAXICODE == symbol) { return 94; } else if (BarcodeFormat.PDF_417 == symbol) { return 57; } else if (BarcodeFormat.QR_CODE == symbol) { return 64; } else if (BarcodeFormat.RSS_14 == symbol) { return 34; } else if (BarcodeFormat.RSS_EXPANDED == symbol) { return 35; } else if (BarcodeFormat.UPC_A == symbol) { return 12; } else if (BarcodeFormat.UPC_E == symbol) { return 9; } else if (BarcodeFormat.UPC_EAN_EXTENSION == symbol) { return 15; } return -1; }
Example 14
Source File: MultiFormatUPCEANReader.java From RipplePower with Apache License 2.0 | 4 votes |
@Override public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType, ?> hints) throws NotFoundException { // Compute this location once and reuse it on multiple implementations int[] startGuardPattern = UPCEANReader.findStartGuardPattern(row); for (UPCEANReader reader : readers) { Result result; try { result = reader.decodeRow(rowNumber, row, startGuardPattern, hints); } catch (ReaderException ignored) { continue; } // Special case: a 12-digit code encoded in UPC-A is identical to a // "0" // followed by those 12 digits encoded as EAN-13. Each will // recognize such a code, // UPC-A as a 12-digit string and EAN-13 as a 13-digit string // starting with "0". // Individually these are correct and their readers will both read // such a code // and correctly call it EAN-13, or UPC-A, respectively. // // In this case, if we've been looking for both types, we'd like to // call it // a UPC-A code. But for efficiency we only run the EAN-13 decoder // to also read // UPC-A. So we special case it here, and convert an EAN-13 result // to a UPC-A // result if appropriate. // // But, don't return UPC-A if UPC-A was not a requested format! boolean ean13MayBeUPCA = result.getBarcodeFormat() == BarcodeFormat.EAN_13 && result.getText().charAt(0) == '0'; @SuppressWarnings("unchecked") Collection<BarcodeFormat> possibleFormats = hints == null ? null : (Collection<BarcodeFormat>) hints.get(DecodeHintType.POSSIBLE_FORMATS); boolean canReturnUPCA = possibleFormats == null || possibleFormats.contains(BarcodeFormat.UPC_A); if (ean13MayBeUPCA && canReturnUPCA) { // Transfer the metdata across Result resultUPCA = new Result(result.getText().substring(1), result.getRawBytes(), result.getResultPoints(), BarcodeFormat.UPC_A); resultUPCA.putAllMetadata(result.getResultMetadata()); return resultUPCA; } return result; } throw NotFoundException.getNotFoundInstance(); }
Example 15
Source File: EAN13Reader.java From Tesseract-OCR-Scanner with Apache License 2.0 | 4 votes |
@Override BarcodeFormat getBarcodeFormat() { return BarcodeFormat.EAN_13; }
Example 16
Source File: RCTCameraViewFinder.java From react-native-camera-face-detector with MIT License | 4 votes |
/** * Parse barcodes as BarcodeFormat constants. * * Supports all iOS codes except [code39mod43, itf14] * * Additionally supports [codabar, maxicode, rss14, rssexpanded, upca, upceanextension] */ private BarcodeFormat parseBarCodeString(String c) { if ("aztec".equals(c)) { return BarcodeFormat.AZTEC; } else if ("ean13".equals(c)) { return BarcodeFormat.EAN_13; } else if ("ean8".equals(c)) { return BarcodeFormat.EAN_8; } else if ("qr".equals(c)) { return BarcodeFormat.QR_CODE; } else if ("pdf417".equals(c)) { return BarcodeFormat.PDF_417; } else if ("upce".equals(c)) { return BarcodeFormat.UPC_E; } else if ("datamatrix".equals(c)) { return BarcodeFormat.DATA_MATRIX; } else if ("code39".equals(c)) { return BarcodeFormat.CODE_39; } else if ("code93".equals(c)) { return BarcodeFormat.CODE_93; } else if ("interleaved2of5".equals(c)) { return BarcodeFormat.ITF; } else if ("codabar".equals(c)) { return BarcodeFormat.CODABAR; } else if ("code128".equals(c)) { return BarcodeFormat.CODE_128; } else if ("maxicode".equals(c)) { return BarcodeFormat.MAXICODE; } else if ("rss14".equals(c)) { return BarcodeFormat.RSS_14; } else if ("rssexpanded".equals(c)) { return BarcodeFormat.RSS_EXPANDED; } else if ("upca".equals(c)) { return BarcodeFormat.UPC_A; } else if ("upceanextension".equals(c)) { return BarcodeFormat.UPC_EAN_EXTENSION; } else { android.util.Log.v("RCTCamera", "Unsupported code.. [" + c + "]"); return null; } }
Example 17
Source File: EAN13Reader.java From barcodescanner-lib-aar with MIT License | 4 votes |
@Override BarcodeFormat getBarcodeFormat() { return BarcodeFormat.EAN_13; }
Example 18
Source File: MultiFormatUPCEANReader.java From reacteu-app with MIT License | 4 votes |
@Override public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException { // Compute this location once and reuse it on multiple implementations int[] startGuardPattern = UPCEANReader.findStartGuardPattern(row); for (UPCEANReader reader : readers) { Result result; try { result = reader.decodeRow(rowNumber, row, startGuardPattern, hints); } catch (ReaderException re) { continue; } // Special case: a 12-digit code encoded in UPC-A is identical to a "0" // followed by those 12 digits encoded as EAN-13. Each will recognize such a code, // UPC-A as a 12-digit string and EAN-13 as a 13-digit string starting with "0". // Individually these are correct and their readers will both read such a code // and correctly call it EAN-13, or UPC-A, respectively. // // In this case, if we've been looking for both types, we'd like to call it // a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read // UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A // result if appropriate. // // But, don't return UPC-A if UPC-A was not a requested format! boolean ean13MayBeUPCA = result.getBarcodeFormat() == BarcodeFormat.EAN_13 && result.getText().charAt(0) == '0'; Collection<BarcodeFormat> possibleFormats = hints == null ? null : (Collection<BarcodeFormat>) hints.get(DecodeHintType.POSSIBLE_FORMATS); boolean canReturnUPCA = possibleFormats == null || possibleFormats.contains(BarcodeFormat.UPC_A); if (ean13MayBeUPCA && canReturnUPCA) { // Transfer the metdata across Result resultUPCA = new Result(result.getText().substring(1), result.getRawBytes(), result.getResultPoints(), BarcodeFormat.UPC_A); resultUPCA.putAllMetadata(result.getResultMetadata()); return resultUPCA; } return result; } throw NotFoundException.getNotFoundInstance(); }
Example 19
Source File: MultiFormatUPCEANReader.java From weex with Apache License 2.0 | 4 votes |
@Override public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException { // Compute this location once and reuse it on multiple implementations int[] startGuardPattern = UPCEANReader.findStartGuardPattern(row); for (UPCEANReader reader : readers) { Result result; try { result = reader.decodeRow(rowNumber, row, startGuardPattern, hints); } catch (ReaderException ignored) { continue; } // Special case: a 12-digit code encoded in UPC-A is identical to a "0" // followed by those 12 digits encoded as EAN-13. Each will recognize such a code, // UPC-A as a 12-digit string and EAN-13 as a 13-digit string starting with "0". // Individually these are correct and their readers will both read such a code // and correctly call it EAN-13, or UPC-A, respectively. // // In this case, if we've been looking for both types, we'd like to call it // a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read // UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A // result if appropriate. // // But, don't return UPC-A if UPC-A was not a requested format! boolean ean13MayBeUPCA = result.getBarcodeFormat() == BarcodeFormat.EAN_13 && result.getText().charAt(0) == '0'; @SuppressWarnings("unchecked") Collection<BarcodeFormat> possibleFormats = hints == null ? null : (Collection<BarcodeFormat>) hints.get(DecodeHintType.POSSIBLE_FORMATS); boolean canReturnUPCA = possibleFormats == null || possibleFormats.contains(BarcodeFormat.UPC_A); if (ean13MayBeUPCA && canReturnUPCA) { // Transfer the metdata across Result resultUPCA = new Result(result.getText().substring(1), result.getRawBytes(), result.getResultPoints(), BarcodeFormat.UPC_A); resultUPCA.putAllMetadata(result.getResultMetadata()); return resultUPCA; } return result; } throw NotFoundException.getNotFoundInstance(); }
Example 20
Source File: EAN13Reader.java From ZXing-Orient with Apache License 2.0 | 4 votes |
@Override BarcodeFormat getBarcodeFormat() { return BarcodeFormat.EAN_13; }