ursus
11/27/2026, 2:50 PMString.toByteArray() → Base64.decode(ByteArray): ByteArray → Android Bitmap.decodeByteArray
however the base64 decode allocates a new buffer, so maybe I can do away with it?
so I want thinking of decoding in place with decodeIntoByteArray passing in source and dest as the same thing
val bytes = "...".toByteArray(UTF_8)
val decodedLength = Base64.decodeIntoByteArray(source = bytes, destination = bytes)
BitmapFactory.decodeByteArray(bytes, 0, decodedLength, options)
seems to work
is it a good idea though?ephemient
11/28/2026, 8:20 AMursus
11/28/2026, 4:53 PMursus
11/28/2026, 4:54 PMpublic fun decode(source: CharSequence, startIndex: Int = 0, endIndex: Int = source.length): ByteArray {
val byteSource = platformCharsToBytes(source, startIndex, endIndex)
return decode(byteSource)
}
public fun decode(source: ByteArray, startIndex: Int = 0, endIndex: Int = source.size): ByteArray {
checkSourceBounds(source.size, startIndex, endIndex)
val decodeSize = decodeSize(source, startIndex, endIndex)
val destination = ByteArray(decodeSize) <----
val bytesWritten = decodeImpl(source, destination, 0, startIndex, endIndex)
check(bytesWritten == destination.size)
return destination
}ursus
11/28/2026, 4:54 PMstring.getBytes for me, afterwards its the same