本文整理汇总了Java中com.google.zxing.FormatException类的典型用法代码示例。如果您正苦于以下问题:Java FormatException类的具体用法?Java FormatException怎么用?Java FormatException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FormatException类属于com.google.zxing包,在下文中一共展示了FormatException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyCodewordCount
import com.google.zxing.FormatException; //导入依赖的package包/类
private static void verifyCodewordCount(int[] codewords, int numECCodewords) throws
FormatException {
if (codewords.length < 4) {
throw FormatException.getFormatInstance();
}
int numberOfCodewords = codewords[0];
if (numberOfCodewords > codewords.length) {
throw FormatException.getFormatInstance();
} else if (numberOfCodewords != 0) {
} else {
if (numECCodewords < codewords.length) {
codewords[0] = codewords.length - numECCodewords;
return;
}
throw FormatException.getFormatInstance();
}
}
示例2: decodeRow
import com.google.zxing.FormatException; //导入依赖的package包/类
@Override
public Result decodeRow(int rowNumber,
BitArray row,
Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {
// Rows can start with even pattern in case in prev rows there where odd number of patters.
// So lets try twice
this.pairs.clear();
this.startFromEven = false;
try {
return constructResult(decodeRow2pairs(rowNumber, row));
} catch (NotFoundException e) {
// OK
}
this.pairs.clear();
this.startFromEven = true;
return constructResult(decodeRow2pairs(rowNumber, row));
}
示例3: constructResult
import com.google.zxing.FormatException; //导入依赖的package包/类
static Result constructResult(List<ExpandedPair> pairs) throws NotFoundException, FormatException {
BitArray binary = BitArrayBuilder.buildBitArray(pairs);
AbstractExpandedDecoder decoder = AbstractExpandedDecoder.createDecoder(binary);
String resultingString = decoder.parseInformation();
ResultPoint[] firstPoints = pairs.get(0).getFinderPattern().getResultPoints();
ResultPoint[] lastPoints = pairs.get(pairs.size() - 1).getFinderPattern().getResultPoints();
return new Result(
resultingString,
null,
new ResultPoint[]{firstPoints[0], firstPoints[1], lastPoints[0], lastPoints[1]},
BarcodeFormat.RSS_EXPANDED
);
}
示例4: parseInformation
import com.google.zxing.FormatException; //导入依赖的package包/类
public String parseInformation() throws NotFoundException, FormatException {
if (getInformation().getSize() < 48) {
throw NotFoundException.getNotFoundInstance();
}
StringBuilder buf = new StringBuilder();
encodeCompressedGtin(buf, 8);
int lastAIdigit = getGeneralDecoder().extractNumericValueFromBitArray(48, 2);
buf.append("(393");
buf.append(lastAIdigit);
buf.append(')');
int firstThreeDigits = getGeneralDecoder().extractNumericValueFromBitArray(50, 10);
if (firstThreeDigits / 100 == 0) {
buf.append('0');
}
if (firstThreeDigits / 10 == 0) {
buf.append('0');
}
buf.append(firstThreeDigits);
buf.append(getGeneralDecoder().decodeGeneralPurposeField(60, null).getNewString());
return buf.toString();
}
示例5: decode
import com.google.zxing.FormatException; //导入依赖的package包/类
private static Result[] decode(BinaryBitmap image, Map<DecodeHintType, ?> hints, boolean
multiple) throws NotFoundException, FormatException, ChecksumException {
List<Result> results = new ArrayList();
PDF417DetectorResult detectorResult = Detector.detect(image, hints, multiple);
for (ResultPoint[] points : detectorResult.getPoints()) {
DecoderResult decoderResult = PDF417ScanningDecoder.decode(detectorResult.getBits(),
points[4], points[5], points[6], points[7], getMinCodewordWidth(points),
getMaxCodewordWidth(points));
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(),
points, BarcodeFormat.PDF_417);
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult
.getECLevel());
PDF417ResultMetadata pdf417ResultMetadata = (PDF417ResultMetadata) decoderResult
.getOther();
if (pdf417ResultMetadata != null) {
result.putMetadata(ResultMetadataType.PDF417_EXTRA_METADATA, pdf417ResultMetadata);
}
results.add(result);
}
return (Result[]) results.toArray(new Result[results.size()]);
}
示例6: parseInformation
import com.google.zxing.FormatException; //导入依赖的package包/类
@Override
public String parseInformation() throws NotFoundException, FormatException {
if (this.getInformation().getSize() < HEADER_SIZE + GTIN_SIZE) {
throw NotFoundException.getNotFoundInstance();
}
StringBuilder buf = new StringBuilder();
encodeCompressedGtin(buf, HEADER_SIZE);
int lastAIdigit =
this.getGeneralDecoder().extractNumericValueFromBitArray(HEADER_SIZE + GTIN_SIZE, LAST_DIGIT_SIZE);
buf.append("(392");
buf.append(lastAIdigit);
buf.append(')');
DecodedInformation decodedInformation =
this.getGeneralDecoder().decodeGeneralPurposeField(HEADER_SIZE + GTIN_SIZE + LAST_DIGIT_SIZE, null);
buf.append(decodedInformation.getNewString());
return buf.toString();
}
示例7: parseECIValue
import com.google.zxing.FormatException; //导入依赖的package包/类
private static int parseECIValue(BitSource bits) throws FormatException {
int firstByte = bits.readBits(8);
if ((firstByte & 0x80) == 0) {
// just one byte
return firstByte & 0x7F;
}
if ((firstByte & 0xC0) == 0x80) {
// two bytes
int secondByte = bits.readBits(8);
return ((firstByte & 0x3F) << 8) | secondByte;
}
if ((firstByte & 0xE0) == 0xC0) {
// three bytes
int secondThirdBytes = bits.readBits(16);
return ((firstByte & 0x1F) << 16) | secondThirdBytes;
}
throw FormatException.getFormatInstance();
}
示例8: decodeAllCodes
import com.google.zxing.FormatException; //导入依赖的package包/类
String decodeAllCodes(StringBuilder buff, int initialPosition) throws NotFoundException, FormatException {
int currentPosition = initialPosition;
String remaining = null;
do{
DecodedInformation info = this.decodeGeneralPurposeField(currentPosition, remaining);
String parsedFields = FieldParser.parseFieldsInGeneralPurpose(info.getNewString());
if (parsedFields != null) {
buff.append(parsedFields);
}
if(info.isRemaining()) {
remaining = String.valueOf(info.getRemainingValue());
} else {
remaining = null;
}
if(currentPosition == info.getNewPosition()) {// No step forward!
break;
}
currentPosition = info.getNewPosition();
}while(true);
return buff.toString();
}
示例9: merge
import com.google.zxing.FormatException; //导入依赖的package包/类
private static DetectionResult merge(DetectionResultRowIndicatorColumn
leftRowIndicatorColumn,
DetectionResultRowIndicatorColumn
rightRowIndicatorColumn) throws
NotFoundException, FormatException {
if (leftRowIndicatorColumn == null && rightRowIndicatorColumn == null) {
return null;
}
BarcodeMetadata barcodeMetadata = getBarcodeMetadata(leftRowIndicatorColumn,
rightRowIndicatorColumn);
if (barcodeMetadata != null) {
return new DetectionResult(barcodeMetadata, BoundingBox.merge(adjustBoundingBox
(leftRowIndicatorColumn), adjustBoundingBox(rightRowIndicatorColumn)));
}
return null;
}
示例10: decode
import com.google.zxing.FormatException; //导入依赖的package包/类
@Override
public Result decode(BinaryBitmap image,
Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {
try {
return doDecode(image, hints);
} catch (NotFoundException nfe) {
boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
if (tryHarder && image.isRotateSupported()) {
BinaryBitmap rotatedImage = image.rotateCounterClockwise();
Result result = doDecode(rotatedImage, hints);
// Record that we found it rotated 90 degrees CCW / 270 degrees CW
Map<ResultMetadataType,?> metadata = result.getResultMetadata();
int orientation = 270;
if (metadata != null && metadata.containsKey(ResultMetadataType.ORIENTATION)) {
// But if we found it reversed in doDecode(), add in that result here:
orientation = (orientation +
(Integer) metadata.get(ResultMetadataType.ORIENTATION)) % 360;
}
result.putMetadata(ResultMetadataType.ORIENTATION, orientation);
// Update result points
ResultPoint[] points = result.getResultPoints();
if (points != null) {
int height = rotatedImage.getHeight();
for (int i = 0; i < points.length; i++) {
points[i] = new ResultPoint(height - points[i].getY() - 1, points[i].getX());
}
}
return result;
} else {
throw nfe;
}
}
}
示例11: decodeAllCodes
import com.google.zxing.FormatException; //导入依赖的package包/类
String decodeAllCodes(StringBuilder buff, int initialPosition) throws NotFoundException,
FormatException {
int currentPosition = initialPosition;
String remaining = null;
while (true) {
DecodedInformation info = decodeGeneralPurposeField(currentPosition, remaining);
String parsedFields = FieldParser.parseFieldsInGeneralPurpose(info.getNewString());
if (parsedFields != null) {
buff.append(parsedFields);
}
if (info.isRemaining()) {
remaining = String.valueOf(info.getRemainingValue());
} else {
remaining = null;
}
if (currentPosition == info.getNewPosition()) {
return buff.toString();
}
currentPosition = info.getNewPosition();
}
}
示例12: decode
import com.google.zxing.FormatException; //导入依赖的package包/类
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
throws NotFoundException, ChecksumException, FormatException {
DecoderResult decoderResult;
if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
BitMatrix bits = extractPureBits(image.getBlackMatrix());
decoderResult = decoder.decode(bits, hints);
} else {
throw NotFoundException.getNotFoundInstance();
}
ResultPoint[] points = NO_POINTS;
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.MAXICODE);
String ecLevel = decoderResult.getECLevel();
if (ecLevel != null) {
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
}
return result;
}
示例13: decode
import com.google.zxing.FormatException; //导入依赖的package包/类
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException, FormatException,
ChecksumException {
Result[] result = decode(image, hints, false);
if (result == null || result.length == 0 || result[0] == null) {
throw NotFoundException.getNotFoundInstance();
}
return result[0];
}
示例14: DecodedNumeric
import com.google.zxing.FormatException; //导入依赖的package包/类
DecodedNumeric(int newPosition, int firstDigit, int secondDigit) throws FormatException {
super(newPosition);
if (firstDigit < 0 || firstDigit > 10 || secondDigit < 0 || secondDigit > 10) {
throw FormatException.getFormatInstance();
}
this.firstDigit = firstDigit;
this.secondDigit = secondDigit;
}
示例15: decode
import com.google.zxing.FormatException; //导入依赖的package包/类
private DecoderResult decode(BitMatrixParser parser, Map<DecodeHintType, ?> hints) throws
FormatException, ChecksumException {
Version version = parser.readVersion();
ErrorCorrectionLevel ecLevel = parser.readFormatInformation().getErrorCorrectionLevel();
DataBlock[] dataBlocks = DataBlock.getDataBlocks(parser.readCodewords(), version, ecLevel);
int totalBytes = 0;
for (DataBlock dataBlock : dataBlocks) {
DataBlock dataBlock2;
totalBytes += dataBlock2.getNumDataCodewords();
}
byte[] resultBytes = new byte[totalBytes];
int resultOffset = 0;
int length = dataBlocks.length;
int i = 0;
while (i < length) {
dataBlock2 = dataBlocks[i];
byte[] codewordBytes = dataBlock2.getCodewords();
int numDataCodewords = dataBlock2.getNumDataCodewords();
correctErrors(codewordBytes, numDataCodewords);
int i2 = 0;
int resultOffset2 = resultOffset;
while (i2 < numDataCodewords) {
resultOffset = resultOffset2 + 1;
resultBytes[resultOffset2] = codewordBytes[i2];
i2++;
resultOffset2 = resultOffset;
}
i++;
resultOffset = resultOffset2;
}
return DecodedBitStreamParser.decode(resultBytes, version, ecLevel, hints);
}