Skip to content

Commit

Permalink
fix: resize bitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
rychardsouzapopcode committed Dec 13, 2021
1 parent a828ec3 commit e49063f
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 38 deletions.
31 changes: 20 additions & 11 deletions .idea/libraries/Dart_SDK.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 23 additions & 4 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion android/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions android/.idea/modules.xml

This file was deleted.

12 changes: 0 additions & 12 deletions android/.idea/runConfigurations.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public class ReadBarcodeFromFile extends AsyncTask<Void, Void, String> {

private static final int NUMBER_OF_ATTEMPTS = 4;
private static final double PORCENTAGEM_ESCALA = 0.05;

@SuppressLint("StaticFieldLeak")
private final Context context;
Expand All @@ -49,6 +50,13 @@ public class ReadBarcodeFromFile extends AsyncTask<Void, Void, String> {
protected void onPreExecute() {
}

private Bitmap resizeImage(Bitmap bitmap, int tryNumber){
int width = (int) (bitmap.getWidth() * (1-tryNumber * PORCENTAGEM_ESCALA));
int height = (int) (bitmap.getHeight() * (1-tryNumber * PORCENTAGEM_ESCALA));
bitmap = Bitmap.createScaledBitmap(bitmap, width,height, false);
return bitmap;
}

@Override
protected String doInBackground(Void... voids) {
if (filePath != null) {
Expand All @@ -59,6 +67,7 @@ protected String doInBackground(Void... voids) {
bitmap = generateImageFromPdf(filePath, 0, tryNumber);
} else {
bitmap = BitmapFactory.decodeFile(filePath.getPath());
bitmap = resizeImage(bitmap, tryNumber);
}
if (bitmap != null) {
String code = scanImage(bitmap, new MultiFormatReader());
Expand Down
1 change: 1 addition & 0 deletions barcode_finder.iml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/build" />
</content>
<orderEntry type="jdk" jdkName="Android API 28 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
Expand Down

0 comments on commit e49063f

Please sign in to comment.