将照片上传到Firebase存储时,如何减小照片的大小?
将照片上传到Firebase存储时,我想减小照片的大小。我的代码中有一个错误。我写了一种尺寸的方法。你能帮忙吗? (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
}
}
第二。
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)
}
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)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论