title: How to convert an image into base64 and also compress it using kotlin in androidX?
body: <p>I am creating an offline SMS app. I want to know how to convert image, chosen by the user, into string base64 and also compressed it.</p>
  
  <p>I have searched a lot but not much material I found.All the data I found is in Java. But I need in Kotlin language.</p>
  
  <p><strong>Activity File</strong></p>
  
  <pre><code>class MainActivity1 :AppCompatActivity(){
  
      private val requestReceiveSms: Int = 1
      private val requestSendSms: Int = 2
      private var mMessageRecycler: RecyclerView? = null
      private var mMessageAdapter: MessageAdapter? = null
  
      val SELECT_PICTURE = 5
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
          btn1.setOnClickListener {
              dispatchGalleryIntent()
          }
  
  
  
          seupRecycler()
  
          val bundle: Bundle? = intent.extras
  
          bundle?.let {
              val NUm = bundle.getString("address")
  
  
  
              phone.text = NUm
          }
  
  
  
          btnSend.setOnClickListener {
  
              if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.SEND_SMS) !=
                  PackageManager.PERMISSION_GRANTED
              ) {
                  ActivityCompat.requestPermissions(
                      this, arrayOf(android.Manifest.permission.SEND_SMS),
                      requestSendSms
                  )
              } else {
                  SendSms()
              }
          }
  
          if(ActivityCompat.checkSelfPermission(this,android.Manifest.permission.RECEIVE_SMS) !=
              PackageManager.PERMISSION_GRANTED){
              ActivityCompat.requestPermissions(this, arrayOf(android.Manifest.permission.RECEIVE_SMS),
                  requestReceiveSms)
          }
      }
  
      private fun seupRecycler() {
          mMessageRecycler = this.reyclerview_message_list as RecyclerView
          mMessageAdapter = MessageAdapter(this)
          val layoutManager = LinearLayoutManager(this)
          layoutManager.orientation = RecyclerView.VERTICAL
      }
  
      override fun onRequestPermissionsResult(requestCode: Int, permissions: Array&lt;out String&gt;,
                                              grantResults: IntArray) {
          if(requestCode == requestSendSms)SendSms()
      }
  
      private fun SendSms() {
  
  
          val str_address = phone
          val str_message = txtMessage.text.toString()
  
  
  
          SmsManager.getDefault().sendTextMessage(str_address.toString(),null,str_message,null,null)
  
          Toast.makeText(this,"SMS Sent", Toast.LENGTH_SHORT).show()
  
  
  
      }
  
      override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
          super.onActivityResult(requestCode, resultCode, data)
          if(requestCode == SELECT_PICTURE &amp;&amp; resultCode == Activity.RESULT_OK){
              try {
  
                  val uri = data!!.data
                  imageView2.setImageURI(uri)
  
              }catch (e : IOException){
                  e.printStackTrace()
              }
          }
      }
      fun dispatchGalleryIntent(){
          val intent = Intent(
              Intent.ACTION_PICK,
              MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
          //intent.type = "image/*"
          //intent.action = Intent.ACTION_GET_CONTENT
          //startActivityForResult(Intent.createChooser(intent,"SELECT IMAGE"), SELECT_PICTURE)
          startActivityForResult(intent,SELECT_PICTURE)
      }
  
  }
  </code></pre>
  
  <p><strong>Expected</strong></p>
  
  <p>Convert image into base64 and compress it.</p>
  
  <p><strong>Actual</strong></p>
  
  <p>Nothing happens.</p>