Home > Blockchain >  How do I save an imageview into the gallery?
How do I save an imageview into the gallery?

Time:01-23

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)

CodePudding user response:

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)

CodePudding user response:

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

  •  Tags:  
  • Related