Tanish Azad
07/22/2024, 10:30 PMTrejkaz
07/23/2024, 1:29 AMTrejkaz
07/23/2024, 1:38 AMTrejkaz
07/23/2024, 1:38 AMimport androidx.compose.foundation.Image
import androidx.compose.material.Surface
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.res.loadImageBitmap
import androidx.compose.ui.window.singleWindowApplication
import java.io.ByteArrayInputStream
fun main() = singleWindowApplication {
val painter = remember {
val byteArray ="""
89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52
00 00 01 00 00 00 01 00 01 03 00 00 00 66 BC 3A
25 00 00 00 03 50 4C 54 45 B5 D0 D0 63 04 16 EA
00 00 00 1F 49 44 41 54 68 81 ED C1 01 0D 00 00
00 C2 A0 F7 4F 6D 0E 37 A0 00 00 00 00 00 00 00
00 BE 0D 21 00 00 01 9A 60 E1 D5 00 00 00 00 49
45 4E 44 AE 42 60 82
"""
.split(Regex("\\s+"))
.filterNot(String::isEmpty)
.map { c -> c.toInt(16).toByte() }
.toByteArray()
BitmapPainter(image = loadImageBitmap(ByteArrayInputStream(byteArray)))
}
Surface {
Image(painter = painter, contentDescription = "Image loaded from in-memory byte array")
}
}
youssef hachicha
07/23/2024, 7:44 AMTanish Azad
07/23/2024, 10:32 AMTrejkaz
07/23/2024, 10:33 AMTrejkaz
07/23/2024, 10:33 AMTanish Azad
07/23/2024, 10:36 AMTrejkaz
07/23/2024, 10:37 AMandroidx.compose.ui.res.loadImageBitmap
Trejkaz
07/23/2024, 10:37 AM/**
* Load and decode [ImageBitmap] from the given [inputStream]. [inputStream] should contain encoded
* raster image in a format supported by Skia (BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP)
*
* @param inputStream input stream to load an rater image. All bytes will be read from this
* stream, but stream will not be closed after this method.
* @return the decoded SVG image associated with the resource
*/
fun loadImageBitmap(inputStream: InputStream): ImageBitmap =
Trejkaz
07/23/2024, 10:37 AM