mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-03-04 23:27:09 -05:00
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.
This commit is contained in:
@@ -21,7 +21,7 @@ import java.lang.ref.WeakReference;
|
||||
class BarcodeImageWriterTask extends AsyncTask<Void, Void, Bitmap>
|
||||
{
|
||||
private static final String TAG = "LoyaltyCardLocker";
|
||||
private static final int MAX_WIDTH = 600;
|
||||
private static final int MAX_WIDTH = 500;
|
||||
|
||||
private final WeakReference<ImageView> imageViewReference;
|
||||
private final String cardId;
|
||||
@@ -37,11 +37,19 @@ class BarcodeImageWriterTask extends AsyncTask<Void, Void, Bitmap>
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user