2 * Copyright 2009 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 using BinaryBitmap = com.google.zxing.BinaryBitmap;
\r
18 using Reader = com.google.zxing.Reader;
\r
19 using ReaderException = com.google.zxing.ReaderException;
\r
20 using Result = com.google.zxing.Result;
\r
21 namespace com.google.zxing.multi
\r
24 /// <summary> This class attempts to decode a barcode from an image, not by scanning the whole image,
\r
25 /// but by scanning subsets of the image. This is important when there may be multiple barcodes in
\r
26 /// an image, and detecting a barcode may find parts of multiple barcode and fail to decode
\r
27 /// (e.g. QR Codes). Instead this scans the four quadrants of the image -- and also the center
\r
28 /// 'quadrant' to cover the case where a barcode is found in the center.
\r
31 /// <seealso cref="GenericMultipleBarcodeReader">
\r
33 public sealed class ByQuadrantReader : Reader
\r
36 //UPGRADE_NOTE: Final was removed from the declaration of 'delegate '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
37 private Reader delegate_Renamed;
\r
39 public ByQuadrantReader(Reader delegate_Renamed)
\r
41 this.delegate_Renamed = delegate_Renamed;
\r
44 public Result decode(BinaryBitmap image)
\r
46 return decode(image, null);
\r
49 public Result decode(BinaryBitmap image, System.Collections.Hashtable hints)
\r
52 int width = image.Width;
\r
53 int height = image.Height;
\r
54 int halfWidth = width / 2;
\r
55 int halfHeight = height / 2;
\r
57 BinaryBitmap topLeft = image.crop(0, 0, halfWidth, halfHeight);
\r
60 return delegate_Renamed.decode(topLeft, hints);
\r
62 catch (ReaderException re)
\r
67 BinaryBitmap topRight = image.crop(halfWidth, 0, halfWidth, halfHeight);
\r
70 return delegate_Renamed.decode(topRight, hints);
\r
72 catch (ReaderException re)
\r
77 BinaryBitmap bottomLeft = image.crop(0, halfHeight, halfWidth, halfHeight);
\r
80 return delegate_Renamed.decode(bottomLeft, hints);
\r
82 catch (ReaderException re)
\r
87 BinaryBitmap bottomRight = image.crop(halfWidth, halfHeight, halfWidth, halfHeight);
\r
90 return delegate_Renamed.decode(bottomRight, hints);
\r
92 catch (ReaderException re)
\r
97 int quarterWidth = halfWidth / 2;
\r
98 int quarterHeight = halfHeight / 2;
\r
99 BinaryBitmap center = image.crop(quarterWidth, quarterHeight, halfWidth, halfHeight);
\r
100 return delegate_Renamed.decode(center, hints);
\r