https://kotlinlang.org logo
Title
m

Michael Paus

02/14/2022, 5:11 PM
I need to create an ImageBitmap from raw ARGB pixels contained in an IntArray. On Android I do this like this
override fun imageBitmapFromArgb(rawArgbImageData: IntArray, width: Int, height: Int): ImageBitmap {
    val image = ImageBitmap(width, height, ImageBitmapConfig.Argb8888, true, ColorSpaces.Srgb)
    image.asAndroidBitmap().setPixels(rawArgbImageData, 0, width, 0, 0, width, height)
    return image
}
but there does not seem to be a suitable way to do the same on desktop. The Skia bitmap does not seem to have a
setPixels
method.
o

olonho

02/14/2022, 5:27 PM
Why not use
Bitmap.makeFromImage(Image.makeFromEncoded(bytes))
?
m

Michael Paus

02/14/2022, 5:52 PM
@olonho Because “encoded” bytes are not the same as “raw” bytes. Encoded bytes refer to the bytes of, e.g., a JPEG file but I have unencoded raw bytes after I did some image processing.
o

olonho

02/14/2022, 5:53 PM
There are similar API for raw pixels in Image