From dd25421b5bf6683de431b9cec7df03fdc1a4ee77 Mon Sep 17 00:00:00 2001 From: yunzhouhua Date: Sun, 11 Nov 2018 19:40:51 +0800 Subject: [PATCH] =?UTF-8?q?1.=E7=AB=96=E5=B1=8F=E6=89=AB=E7=A0=81=202.?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0DataMatrix=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/codeStyles/Project.xml | 29 +++++++++++ .../qrcodelib/zxing/decode/DecodeHandler.java | 48 +++++++++++++------ .../qrcodelib/zxing/decode/DecodeThread.java | 1 + 3 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 .idea/codeStyles/Project.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/qrcodelib/src/main/java/com/yunzhou/qrcodelib/zxing/decode/DecodeHandler.java b/qrcodelib/src/main/java/com/yunzhou/qrcodelib/zxing/decode/DecodeHandler.java index c1d3cd2..c27266e 100644 --- a/qrcodelib/src/main/java/com/yunzhou/qrcodelib/zxing/decode/DecodeHandler.java +++ b/qrcodelib/src/main/java/com/yunzhou/qrcodelib/zxing/decode/DecodeHandler.java @@ -17,6 +17,7 @@ package com.yunzhou.qrcodelib.zxing.decode; import android.graphics.Bitmap; +import android.graphics.Point; import android.graphics.Rect; import android.hardware.Camera.Size; import android.os.Bundle; @@ -90,20 +91,20 @@ public void handleMessage(Message message) { private void decode(byte[] data, int width, int height) { Size size = activity.getCameraManager().getPreviewSize(); - // 这里需要将获取的data翻转一下,因为相机默认拿的的横屏的数据 - byte[] rotatedData = new byte[data.length]; - for (int y = 0; y < size.height; y++) { - for (int x = 0; x < size.width; x++) - rotatedData[x * size.height + size.height - y - 1] = data[x + y * size.width]; - } - - // 宽高也要调整 - int tmp = size.width; - size.width = size.height; - size.height = tmp; +// // 这里需要将获取的data翻转一下,因为相机默认拿的的横屏的数据 +// byte[] rotatedData = new byte[data.length]; +// for (int y = 0; y < size.height; y++) { +// for (int x = 0; x < size.width; x++) +// rotatedData[x * size.height + size.height - y - 1] = data[x + y * size.width]; +// } +// +// // 宽高也要调整 +// int tmp = size.width; +// size.width = size.height; +// size.height = tmp; Result rawResult = null; - PlanarYUVLuminanceSource source = buildLuminanceSource(rotatedData, size.width, size.height); + PlanarYUVLuminanceSource source = buildLuminanceSource(data, size.width, size.height); if (source != null) { BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); try { @@ -149,8 +150,25 @@ public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int return null; } // Go ahead and assume it's YUV rather than die. - return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect - .height(), false); - } +// return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect +// .height(), false); + + PlanarYUVLuminanceSource source = null; + +// Point point = configManager.getScreenResolution(); + // 这里需要将获取的data翻转一下,因为相机默认拿的的横屏的数据 + byte[] rotatedData = new byte[data.length]; + int newWidth = height; + int newHeight = width; + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + rotatedData[x * newWidth + newWidth - 1 - y] = data[x + y * width]; + } + source = new PlanarYUVLuminanceSource(rotatedData, newWidth, newHeight, rect.left, rect.top, rect.width(), rect.height(), false); + } + + return source; + + } } diff --git a/qrcodelib/src/main/java/com/yunzhou/qrcodelib/zxing/decode/DecodeThread.java b/qrcodelib/src/main/java/com/yunzhou/qrcodelib/zxing/decode/DecodeThread.java index 883c5b9..42b7a4d 100644 --- a/qrcodelib/src/main/java/com/yunzhou/qrcodelib/zxing/decode/DecodeThread.java +++ b/qrcodelib/src/main/java/com/yunzhou/qrcodelib/zxing/decode/DecodeThread.java @@ -58,6 +58,7 @@ public DecodeThread(IScanQRCode activity, int decodeMode) { Collection decodeFormats = new ArrayList(); decodeFormats.addAll(EnumSet.of(BarcodeFormat.AZTEC)); decodeFormats.addAll(EnumSet.of(BarcodeFormat.PDF_417)); + decodeFormats.addAll(EnumSet.of(BarcodeFormat.DATA_MATRIX)); switch (decodeMode) { case BARCODE_MODE: