I want a button to be clicked that saves an image view to the android devices gallery in kotlin. I have this
val image = findViewById<ImageView>(R.id.QRImage)
I want a button to be clicked that saves an image view to the android devices gallery in kotlin. I have this
val image = findViewById<ImageView>(R.id.QRImage)
You can convert your image to bitmap first like the code below:
val image = findViewById<ImageView>(R.id.QRImage)
val imageBitmap = image.drawable.toBitmap()
Then save the bitmap where you want like the code below:
val fileOutputStream = FileOutputStream("Location") //location of the image
imageBitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream)
or save it directly like the code below:
MediaStore.Images.Media.insertImage(context.contentResolver, imageBitmap, "Image title ", null)
I think, this should work:
MediaStore.Images.Media.insertImage(getContentResolver(), yourBitmap, yourTitle , yourDescription);
Also, it is written in this question: android - save image into gallery