2 * Copyright 2009 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.multi.qrcode;
19 import com.google.zxing.BarcodeFormat;
20 import com.google.zxing.MonochromeBitmapSource;
21 import com.google.zxing.ReaderException;
22 import com.google.zxing.Result;
23 import com.google.zxing.ResultMetadataType;
24 import com.google.zxing.ResultPoint;
25 import com.google.zxing.common.DecoderResult;
26 import com.google.zxing.common.DetectorResult;
27 import com.google.zxing.multi.MultipleBarcodeReader;
28 import com.google.zxing.multi.qrcode.detector.MultiDetector;
29 import com.google.zxing.qrcode.QRCodeReader;
31 import java.util.Hashtable;
32 import java.util.Vector;
35 * This implementation can detect and decode multiple QR Codes in an image.
38 * @author Hannes Erven
40 public final class QRCodeMultiReader extends QRCodeReader implements MultipleBarcodeReader {
42 private static final Result[] EMPTY_RESULT_ARRAY = new Result[0];
44 public Result[] decodeMultiple(MonochromeBitmapSource image) throws ReaderException {
45 return decodeMultiple(image, null);
48 public Result[] decodeMultiple(MonochromeBitmapSource image, Hashtable hints) throws ReaderException {
49 Vector results = new Vector();
50 DetectorResult[] detectorResult = new MultiDetector(image).detectMulti(hints);
51 for (int i = 0; i < detectorResult.length; i++) {
53 DecoderResult decoderResult = getDecoder().decode(detectorResult[i].getBits());
54 ResultPoint[] points = detectorResult[i].getPoints();
55 Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE);
56 if (decoderResult.getByteSegments() != null) {
57 result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.getByteSegments());
59 results.addElement(result);
60 } catch (ReaderException re) {
61 // ignore and continue
64 if (results.isEmpty()) {
65 return EMPTY_RESULT_ARRAY;
67 Result[] resultArray = new Result[results.size()];
68 for (int i = 0; i < results.size(); i++) {
69 resultArray[i] = (Result) results.elementAt(i);