I want to limit the resulting Image from the ImputStream to < 10K (Android, Kotlin)


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?

0
Jul 16 at 10:14 AM
User AvatarCryptoCode
#android#kotlin

No answer found for this question yet.