com.google.zxing.BarcodeFormat# EAN_13 ( ) 源码实例Demo

下面列出了com.google.zxing.BarcodeFormat# EAN_13 ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。


/**
 * 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);
        }
      }
    }
  }
}
 
源代码2 项目: RipplePower   文件: ISBNResultParser.java

/**
 * 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);
}
 
源代码3 项目: RipplePower   文件: ProductResultParser.java

@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);
}
 
源代码4 项目: weex   文件: ProductResultParser.java

@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);
}
 

@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);
}
 

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;
}
 

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;
}
 
源代码8 项目: reacteu-app   文件: EAN13Writer.java

@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);
}
 
源代码9 项目: Viewer   文件: BarcodeResult.java

/**
 * @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;
}
 
源代码10 项目: SecScanQR   文件: GeneralHandler.java

/**
 * 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;
}
 
源代码11 项目: Tesseract-OCR-Scanner   文件: EAN13Writer.java

@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);
}
 
源代码12 项目: QrCodeScanner   文件: EAN13Writer.java

@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);
}
 
源代码13 项目: ZXing-Orient   文件: EAN13Writer.java

@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);
}
 

@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();
}
 

@Override
BarcodeFormat getBarcodeFormat() {
  return BarcodeFormat.EAN_13;
}
 

@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();
}
 
源代码17 项目: Tesseract-OCR-Scanner   文件: EAN13Reader.java

@Override
BarcodeFormat getBarcodeFormat() {
  return BarcodeFormat.EAN_13;
}
 

/**
 * 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;
    }
}
 
源代码19 项目: weex   文件: MultiFormatUPCEANReader.java

@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();
}
 
源代码20 项目: ZXing-Orient   文件: EAN13Reader.java

@Override
BarcodeFormat getBarcodeFormat() {
  return BarcodeFormat.EAN_13;
}