From 824a72b156708973e56fab25bb726fc2e771a1b9 Mon Sep 17 00:00:00 2001 From: Branden Archer Date: Tue, 11 Jul 2017 23:16:26 -0400 Subject: [PATCH] Scale height of barcode to match ratio when reducing width When reducing the pixel size of the width, if the height is not scaled to match then 1D barcodes end up being squished and are too narrow to scan. To avoid this, scale the height to match. Then, when the barcode is loaded into a Bitmap it will scale up to the correct size. It was found that on a Galaxy S4 a barcode width of 400 px started to see some blurriness, but 500 px still looked sharp. Reducing the maximum width to 500 px. --- .../card_locker/BarcodeImageWriterTask.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java b/app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java index fcec51eac..474dc0298 100644 --- a/app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java +++ b/app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java @@ -21,7 +21,7 @@ import java.lang.ref.WeakReference; class BarcodeImageWriterTask extends AsyncTask { private static final String TAG = "LoyaltyCardLocker"; - private static final int MAX_WIDTH = 600; + private static final int MAX_WIDTH = 500; private final WeakReference imageViewReference; private final String cardId; @@ -37,11 +37,19 @@ class BarcodeImageWriterTask extends AsyncTask cardId = cardIdString; format = barcodeFormat; - imageHeight = imageView.getHeight(); - // No matter how long the window is, there is only so much space - // needed for the barcode. Put a limit on it to reduce memory usage - imageWidth = Math.min(imageView.getWidth(), MAX_WIDTH); + if(imageView.getWidth() < MAX_WIDTH) + { + imageHeight = imageView.getHeight(); + imageWidth = imageView.getWidth(); + } + else + { + // Scale down the image to reduce the memory needed to produce it + imageWidth = MAX_WIDTH; + double ratio = (double)MAX_WIDTH / (double)imageView.getWidth(); + imageHeight = (int)(imageView.getHeight() * ratio); + } } public Bitmap doInBackground(Void... params)