I have an app where the user can create an event and upload an image from their gallery and upload it to FirebaseStorage. Everything is working fine but the images are really big in size and i'd like to optimize the loading/downloading process. I've already tried with this :
// Get the data from an ImageView as bytes
imageView.setDrawingCacheEnabled(true);
imageView.buildDrawingCache();
Bitmap bitmap = imageView.getDrawingCache();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] data = baos.toByteArray();
UploadTask uploadTask = mountainsRef.putBytes(data);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle unsuccessful uploads
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// taskSnapshot.getMetadata() contains file metadata such as size, content-type
Uri downloadUrl = taskSnapshot.getDownloadUrl();
}
});
and setting bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos);
This works but this basically makes every image ugly.
Is there a way, with a guide if possible, to reduce the size of the image without completely destroying the quality ?