I'm using androidX to take a picture from the camera. As the quality of the image will depend on the camera , larger picture are taking longer time to upload to the server. So there a way for me to compress the image. Note: there is not bitmap and i do not want to convert it bitmap to compress it.
here is how i'm capturing the image.
private void takePicture() {
if (imageCapture != null) {
ByteArrayOutputStream result = new ByteArrayOutputStream();
getCacheDir();
imageCapture.takePicture(new ImageCapture.OutputFileOptions.Builder(result).build(),
Executors.newSingleThreadExecutor(),
new ImageCapture.OnImageSavedCallback() {
@Override
public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
File cache = new File(getCacheDir().getAbsolutePath() + "/" + "captured.png" );
try (FileOutputStream stream = new FileOutputStream(cache)) {
stream.write(result.toByteArray());
uploadImage(cache);
finish();
} catch (Exception e) {
Log.e(TAG, "onImageSaved: Exception occurred", e);
}
}
@Override
public void onError(@NonNull ImageCaptureException exception) {
Log.i(TAG, "onError: ", exception);
}
});
}
}
what would be the best way to compress the image without sacrificing on quality.