Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Pass tests
  • Loading branch information
beroso committed Jan 12, 2023
commit ae3e929df43183dcf29a47208a3eae54496b9c81
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.util.Size;
import androidx.annotation.Nullable;
import java.io.ByteArrayOutputStream;
import java.io.File;
Expand Down Expand Up @@ -47,8 +48,13 @@ String resizeImageIfNeeded(
try {
String[] pathParts = imagePath.split("/");
String imageName = pathParts[pathParts.length - 1];
options.inSampleSize =
calculateInSampleSize(options, maxWidth.intValue(), maxHeight.intValue());
Size size =
calculateSize(
Double.valueOf(options.outWidth),
Double.valueOf(options.outHeight),
maxWidth,
maxHeight);
options.inSampleSize = calculateInSampleSize(options, size.getWidth(), size.getHeight());
options.inJustDecodeBounds = false;
File file =
resizedImage(
Expand All @@ -70,6 +76,15 @@ private File resizedImage(
imageQuality = 100;
}

Size size = calculateSize(originalWidth, originalHeight, maxWidth, maxHeight);
Bitmap scaledBmp = createScaledBitmap(bmp, size.getWidth(), size.getHeight(), false);
File file =
createImageOnExternalDirectory("/scaled_" + outputImageName, scaledBmp, imageQuality);
return file;
}

private Size calculateSize(
Double originalWidth, Double originalHeight, Double maxWidth, Double maxHeight) {
boolean hasMaxWidth = maxWidth != null;
boolean hasMaxHeight = maxHeight != null;

Expand Down Expand Up @@ -105,10 +120,7 @@ private File resizedImage(
}
}

Bitmap scaledBmp = createScaledBitmap(bmp, width.intValue(), height.intValue(), false);
File file =
createImageOnExternalDirectory("/scaled_" + outputImageName, scaledBmp, imageQuality);
return file;
return new Size(width.intValue(), height.intValue());
}

private File createFile(File externalFilesDirectory, String child) {
Expand Down