skip to Main Content

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)

2

Answers


  1. 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)
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search