Skip to content

Commit

Permalink
Merge pull request #17 from spoonconsulting/cater-android-10-less
Browse files Browse the repository at this point in the history
android less than 11 compression bitmap
  • Loading branch information
dinitri authored May 10, 2024
2 parents 32def42 + c6a131a commit 9abd8e6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/android/SpectrumManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ private void transcodeImage(String path, int size, CallbackContext callbackConte
String destinationPath = sourcePath.replace(file.getName(), destinationFileName);
File outputFile = new File(destinationPath);

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
callbackContext.error("Cannot compress image on Android version < 11");
return;
}

try (FileOutputStream out = new FileOutputStream(outputFile)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 80, out)) {
callbackContext.error("Failed to compress image");
return;
}
if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 80, out)) {
callbackContext.error("Failed to compress image");
return;
}
} catch (Exception e) {
callbackContext.error("Failed to save compressed image: " + e.getMessage());
Expand Down

0 comments on commit 9abd8e6

Please sign in to comment.