'How do I reduce the size of a photo when uploading a photo to Firebase storage?
I want to reduce the size of the photo when uploading photos to Firebase storage. There is an error in my codes. I wrote a method for sizing. Can you help? (kotlin)
auth.createUserWithEmailAndPassword(email, password).addOnCompleteListener { task ->
if (task.isSuccessful && task.isComplete) {
val userEmailInfo = auth.currentUser!!.email
val currentUser = auth.currentUser
currentUser.let { firebaseUser ->
val storage = Firebase.storage
val reference = storage.reference
val userPicRef = reference.child(userEmailInfo!!).child("profilPicture")
userPicRef.putFile(selectedPicture!!).addOnSuccessListener { taskSnapshot ->
val uploadPicRef = storage.reference.child(userEmailInfo).child("profilPicture")
uploadPicRef.downloadUrl.addOnSuccessListener {
val profilPicUrl = it.toString()
val userPic = hashMapOf<String, Any>()
userPic["profilPic"] = profilPicUrl
}
}
second.
private fun makeSmallerBitmap(image: Bitmap, maximumSize: Int): Bitmap {
var width = image.width
var height = image.height
val bitmapRatio: Double = width.toDouble() / height.toDouble()
if (bitmapRatio > 1) {
width = maximumSize
val scaledHeight = width / bitmapRatio
height = scaledHeight.toInt()
} else {
height = maximumSize
val scaledWidth = height * bitmapRatio
width = scaledWidth.toInt()
}
return Bitmap.createScaledBitmap(image, width, height, true)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|