First of all, my humble appreciation for the fantastic tutorial. I have searched the net so much and never came across the tutorial which I was exactly looking for until I found this amazing video. I sometimes really wonder why other developers who promise to teach you in very easy steps keep complicating things, while your approach was so smooth and up to the mark I found many video, either they still keep using deprecated methods or teach you something that is really not practical. I saw one of the tutors teaching how to save in the firestore storage and then pull the image back to the imageview, AFTER UPLOADING. Seriously??? then I had to search bac and forth just to find the exact video, like I said before, to teach the steps in a way that as it should be. Thank you very much, jazakallahu khair, may Allah reward you for this social service that you are doing, aameen!
Dear Sir. I have a question. I run android studio on genymotion xiaomi note 7 virtual machine device. But there are no photos in that virtual machine. So how do I download the photos I want?
To save a drawable image to Firebase Storage in Jetpack Compose, you can follow these steps: Add Dependencies: Ensure you have the Firebase Storage dependency in your build.gradle file: groovy Copy code implementation 'com.google.firebase:firebase-storage-ktx:' Get the Drawable: Load your drawable resource. You can convert it to a Bitmap, which is necessary for uploading to Firebase. kotlin Copy code import android.graphics.Bitmap import android.graphics.drawable.Drawable import androidx.compose.ui.res.painterResource import androidx.compose.ui.platform.LocalContext import android.graphics.drawable.BitmapDrawable @Composable fun getBitmapFromDrawable(drawableId: Int): Bitmap? { val context = LocalContext.current val drawable: Drawable = painterResource(id = drawableId).toBitmapDrawable(context) return (drawable as? BitmapDrawable)?.bitmap } fun Drawable.toBitmapDrawable(context: Context): Drawable { return BitmapDrawable(context.resources, Bitmap.createBitmap(intrinsicWidth, intrinsicHeight, Bitmap.Config.ARGB_8888)) } Upload to Firebase: Once you have the Bitmap, you can upload it to Firebase Storage. Convert the Bitmap to a ByteArray before uploading. kotlin Copy code import com.google.firebase.storage.FirebaseStorage import java.io.ByteArrayOutputStream fun uploadImageToFirebase(bitmap: Bitmap, imageName: String) { val storageReference = FirebaseStorage.getInstance().reference.child("images/$imageName") val baos = ByteArrayOutputStream() bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos) val data = baos.toByteArray() val uploadTask = storageReference.putBytes(data) uploadTask.addOnSuccessListener { // Handle successful upload }.addOnFailureListener { exception -> // Handle unsuccessful uploads } } Combine Everything: You can combine these functions in your Composable to save the drawable image when needed: kotlin Copy code @Composable fun SaveImage() { val bitmap = getBitmapFromDrawable(R.drawable.your_image) bitmap?.let { uploadImageToFirebase(it, "your_image_name.jpg") } } Summary: Load the drawable as a Bitmap. Convert the Bitmap to a ByteArray. Upload it to Firebase Storage.
Does this only work on fragments? I do not use fragments. the code works great with one exception? Would you know why my gallery does not come up like your did? mine for some reason does not show the gallery for me to choose a picture? it show stuff like Bug Report -- Drive - My files - Onedrive - System traces But No Gallery at all??? In My part where is Says at the top _ Open from - it only has recent then images then downloads then my phone name then the above mentioned items but no Gallery. if I choose Images - I do see my phone images but the are faded or greyed out and I can not select any of the images?? Please help if you can with this issue and thank-you
how to retrieve images from the firestore: ruclips.net/video/_eTZowmape8/видео.html
Underrated and You are a life saver.. Thank you so much for this
You're welcome
First of all, my humble appreciation for the fantastic tutorial.
I have searched the net so much and never came across the tutorial which I was exactly looking for until I found this amazing video. I sometimes really wonder why other developers who promise to teach you in very easy steps keep complicating things, while your approach was so smooth and up to the mark
I found many video, either they still keep using deprecated methods or teach you something that is really not practical. I saw one of the tutors teaching how to save in the firestore storage and then pull the image back to the imageview, AFTER UPLOADING. Seriously??? then I had to search bac and forth just to find the exact video, like I said before, to teach the steps in a way that as it should be.
Thank you very much, jazakallahu khair, may Allah reward you for this social service that you are doing, aameen!
Thank you very much.
what a great video sir, its very useful for me and also waiting for next video of part 2 on retrieve image in RV
You're welcome. Sub for next if you haven't already done. And recommend the channel to your friends.
here you have it: ruclips.net/video/_eTZowmape8/видео.html
thanks for it
You're welcome. Subscribe for more. I'm going to make the same playlist for Jetpack Compose.
ایرانی پرچمش بالاس🤙🏻
فدای شما
من یه کانال فارسی هم دارم اگر دوست دارید اونو سابسکرایب کنید. اندروید گیک رو سرچ کنید پیداش میکنید.
Dear Sir. I have a question. I run android studio on genymotion xiaomi note 7 virtual machine device. But there are no photos in that virtual machine. So how do I download the photos I want?
You can download them by your pc then transfer them in the emulator.
How to save drawable image in firebase in compose ??pls explain
To save a drawable image to Firebase Storage in Jetpack Compose, you can follow these steps:
Add Dependencies: Ensure you have the Firebase Storage dependency in your build.gradle file:
groovy
Copy code
implementation 'com.google.firebase:firebase-storage-ktx:'
Get the Drawable: Load your drawable resource. You can convert it to a Bitmap, which is necessary for uploading to Firebase.
kotlin
Copy code
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.platform.LocalContext
import android.graphics.drawable.BitmapDrawable
@Composable
fun getBitmapFromDrawable(drawableId: Int): Bitmap? {
val context = LocalContext.current
val drawable: Drawable = painterResource(id = drawableId).toBitmapDrawable(context)
return (drawable as? BitmapDrawable)?.bitmap
}
fun Drawable.toBitmapDrawable(context: Context): Drawable {
return BitmapDrawable(context.resources, Bitmap.createBitmap(intrinsicWidth, intrinsicHeight, Bitmap.Config.ARGB_8888))
}
Upload to Firebase: Once you have the Bitmap, you can upload it to Firebase Storage. Convert the Bitmap to a ByteArray before uploading.
kotlin
Copy code
import com.google.firebase.storage.FirebaseStorage
import java.io.ByteArrayOutputStream
fun uploadImageToFirebase(bitmap: Bitmap, imageName: String) {
val storageReference = FirebaseStorage.getInstance().reference.child("images/$imageName")
val baos = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos)
val data = baos.toByteArray()
val uploadTask = storageReference.putBytes(data)
uploadTask.addOnSuccessListener {
// Handle successful upload
}.addOnFailureListener { exception ->
// Handle unsuccessful uploads
}
}
Combine Everything: You can combine these functions in your Composable to save the drawable image when needed:
kotlin
Copy code
@Composable
fun SaveImage() {
val bitmap = getBitmapFromDrawable(R.drawable.your_image)
bitmap?.let {
uploadImageToFirebase(it, "your_image_name.jpg")
}
}
Summary:
Load the drawable as a Bitmap.
Convert the Bitmap to a ByteArray.
Upload it to Firebase Storage.
Does this only work on fragments? I do not use fragments. the code works great with one exception? Would you know why my gallery does not come up like your did? mine for some reason does not show the gallery for me to choose a picture? it show stuff like Bug Report -- Drive - My files - Onedrive - System traces But No Gallery at all??? In My part where is Says at the top _ Open from - it only has recent then images then downloads then my phone name then the above mentioned items but no Gallery.
if I choose Images - I do see my phone images but the are faded or greyed out and I can not select any of the images?? Please help if you can with this issue and thank-you
Hey. You can use it on activities as well. I do not know what is wrong with your gallery.
how to convert it to firestore
Please reply
I don't understand what do you mean. Firebase storage is called firestore.
If you want to fetch the image to the phone watch this video ruclips.net/video/_eTZowmape8/видео.html