I need to save the encoded image as a string in a database and need to possibly "shrink" a large one to less than 10k witout writing it to file.
@Throws(IOException::class)
fun Uri.getByteArrayStringFromUri(context: Context): String {
val iStream: InputStream? = context.contentResolver.openInputStream(this)
val imageByteArray: ByteArray? = iStream?.readBytes()
iStream?.close()
return Base64.getEncoder().encodeToString((Binary(BsonBinarySubType.BINARY, imageByteArray).data))
}
Optional:
I can also supply a Bitmap instead of an Uri and possibly resize it in memory?