Take picture and convert to Base64

后端 未结 4 1143
陌清茗
陌清茗 2020-12-14 02:24

I use code below to make a picture with camera. Instead of saving I would like to encode it to Base64 and after that pass it to another API as an input. I can\'

4条回答
  •  没有蜡笔的小新
    2020-12-14 03:05

    Just for converting from bitmap to base64 string in kotlin I use:

    private fun encodeImage(bm: Bitmap): String? {
            val baos = ByteArrayOutputStream()
            bm.compress(Bitmap.CompressFormat.JPEG, 100, baos)
            val b = baos.toByteArray()
            return Base64.encodeToString(b, Base64.DEFAULT)
        }
    

提交回复
热议问题