From ea20c0053947b8e9d4532923f45bf37f50770c85 Mon Sep 17 00:00:00 2001 From: allen2015555 Date: Thu, 18 Oct 2018 14:14:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=9B=BE=E7=89=87=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E4=BA=8C=E7=BB=B4=E7=A0=81=E5=8E=8B=E7=BC=A9=E5=9B=BE?= =?UTF-8?q?=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/compiler.xml | 22 ---------------- .idea/copyright/profiles_settings.xml | 3 --- .idea/misc.xml | 9 ++++--- .../zxing/client/android/CaptureActivity.java | 1 + .../client/android/utils/ZXingUtils.java | 26 ++++++++++++++++++- .../main/res/drawable/mn_scan_dialog_bg.xml | 15 ----------- .../src/main/res/layout/mn_scan_capture.xml | 12 ++------- 7 files changed, 33 insertions(+), 55 deletions(-) delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/copyright/profiles_settings.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 96cc43e..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index ba7052b..99202cc 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,11 +5,12 @@ @@ -24,7 +25,7 @@ - + diff --git a/libraryzxing/src/main/java/com/google/zxing/client/android/CaptureActivity.java b/libraryzxing/src/main/java/com/google/zxing/client/android/CaptureActivity.java index 7ba3499..48319f4 100755 --- a/libraryzxing/src/main/java/com/google/zxing/client/android/CaptureActivity.java +++ b/libraryzxing/src/main/java/com/google/zxing/client/android/CaptureActivity.java @@ -216,6 +216,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { new Thread(new Runnable() { @Override public void run() { + //需要压缩图片 Bitmap bitmapChoose = ZXingUtils.decodeUriAsBitmap(CaptureActivity.this, uri); if (bitmapChoose != null) { final String decodeQRCodeFromBitmap = ZXingUtils.syncDecodeQRCode(bitmapChoose); diff --git a/libraryzxing/src/main/java/com/google/zxing/client/android/utils/ZXingUtils.java b/libraryzxing/src/main/java/com/google/zxing/client/android/utils/ZXingUtils.java index 1b42927..6cf4da8 100644 --- a/libraryzxing/src/main/java/com/google/zxing/client/android/utils/ZXingUtils.java +++ b/libraryzxing/src/main/java/com/google/zxing/client/android/utils/ZXingUtils.java @@ -271,7 +271,14 @@ public static String recode(String str) { public static Bitmap decodeUriAsBitmap(Context context, Uri uri) { Bitmap bitmap = null; try { - bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri)); +// bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri)); + //压缩图片 + final BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri), null, options); + options.inSampleSize = calculateInSampleSize(options, 720, 1280); + options.inJustDecodeBounds = false; + bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri), null, options); } catch (FileNotFoundException e) { e.printStackTrace(); return null; @@ -279,4 +286,21 @@ public static Bitmap decodeUriAsBitmap(Context context, Uri uri) { return bitmap; } + //计算图片的缩放值 + public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { + final int height = options.outHeight; + final int width = options.outWidth; + int inSampleSize = 1; + if (height > reqHeight || width > reqWidth) { + //使用需要的宽高的最大值来计算比率 + final int suitedValue = reqHeight > reqWidth ? reqHeight : reqWidth; + final int heightRatio = Math.round((float) height / (float) suitedValue); + final int widthRatio = Math.round((float) width / (float) suitedValue); + + inSampleSize = heightRatio > widthRatio ? heightRatio : widthRatio;//用最大 + } + return inSampleSize; + } + + } diff --git a/libraryzxing/src/main/res/drawable/mn_scan_dialog_bg.xml b/libraryzxing/src/main/res/drawable/mn_scan_dialog_bg.xml index 2e558e4..f90c1ca 100644 --- a/libraryzxing/src/main/res/drawable/mn_scan_dialog_bg.xml +++ b/libraryzxing/src/main/res/drawable/mn_scan_dialog_bg.xml @@ -15,19 +15,4 @@ - - - - - \ No newline at end of file diff --git a/libraryzxing/src/main/res/layout/mn_scan_capture.xml b/libraryzxing/src/main/res/layout/mn_scan_capture.xml index e6ce357..9184155 100755 --- a/libraryzxing/src/main/res/layout/mn_scan_capture.xml +++ b/libraryzxing/src/main/res/layout/mn_scan_capture.xml @@ -103,8 +103,8 @@ android:visibility="visible"> - -