diff --git a/zxing/src/main/java/cn/bingoogolapple/qrcode/zxing/ZXingView.java b/zxing/src/main/java/cn/bingoogolapple/qrcode/zxing/ZXingView.java index 37041f2..567d0b3 100644 --- a/zxing/src/main/java/cn/bingoogolapple/qrcode/zxing/ZXingView.java +++ b/zxing/src/main/java/cn/bingoogolapple/qrcode/zxing/ZXingView.java @@ -10,6 +10,7 @@ import com.google.zxing.BarcodeFormat; import com.google.zxing.BinaryBitmap; import com.google.zxing.DecodeHintType; +import com.google.zxing.LuminanceSource; import com.google.zxing.MultiFormatReader; import com.google.zxing.PlanarYUVLuminanceSource; import com.google.zxing.Result; @@ -27,6 +28,8 @@ public class ZXingView extends QRCodeView { private MultiFormatReader mMultiFormatReader; private Map mHintMap; + private boolean isInvertSupported = false; + private long counter = 0; public ZXingView(Context context, AttributeSet attributeSet) { this(context, attributeSet, 0); @@ -75,6 +78,16 @@ public void setType(BarcodeType barcodeType, Map hintMap setupReader(); } + public void enableInvertCode() { + isInvertSupported = true; + } + + @Override + public void startSpot() { + counter = 0; + super.startSpot(); + } + @Override protected ScanResult processBitmapData(Bitmap bitmap) { return new ScanResult(QRCodeDecoder.syncDecodeQRCode(bitmap)); @@ -85,8 +98,9 @@ protected ScanResult processData(byte[] data, int width, int height, boolean isR Result rawResult = null; Rect scanBoxAreaRect = null; + counter++; try { - PlanarYUVLuminanceSource source; + LuminanceSource source; scanBoxAreaRect = mScanBoxView.getScanBoxAreaRect(height); if (scanBoxAreaRect != null) { source = new PlanarYUVLuminanceSource(data, width, height, scanBoxAreaRect.left, scanBoxAreaRect.top, scanBoxAreaRect.width(), @@ -95,6 +109,10 @@ protected ScanResult processData(byte[] data, int width, int height, boolean isR source = new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false); } + if (counter % 2 == 0 && isInvertSupported) { + source = source.invert(); + } + rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new GlobalHistogramBinarizer(source))); if (rawResult == null) { rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(source))); @@ -141,4 +159,4 @@ protected ScanResult processData(byte[] data, int width, int height, boolean isR private boolean isNeedAutoZoom(BarcodeFormat barcodeFormat) { return isAutoZoom() && barcodeFormat == BarcodeFormat.QR_CODE; } -} \ No newline at end of file +}