Android – how do I reduce the size of an image before uploading it to firebase storage?

I have made a social application for image and video sharing. However, it takes too much time to load images. I am using the sliding library. Please tell me how to reduce the size of images picked up from the library without considerable changes in image quality (such as instagram), and then upload them to firebase storage. Please help!

resolvent:

StorageReference childRef2 = [your firebase storage path]
storageRef.child(UserDetails.username+"profilepic.jpg");
                    Bitmap bmp = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    bmp.compress(Bitmap.CompressFormat.JPEG, 25, baos);
                    byte[] data = baos.toByteArray();
                    //uploading the image
                    UploadTask uploadTask2 = childRef2.putBytes(data);
                    uploadTask2.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                        @Override
                        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                            Toast.makeText(Profilepic.this, "Upload successful", Toast.LENGTH_LONG).show();
                        }
                    }).addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Toast.makeText(Profilepic.this, "Upload Failed -> " + e, Toast.LENGTH_LONG).show();
                        }
                    });`

Just continue and perform the above steps. It will reduce your image size and upload it to firebase. It will reduce the image size to 1 to 2 Mb, just as in my experience, the 4MB file has become 304kb

Filepath is the file object associated with the selected image

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>