How to create ImageBitmap by array with points and...
# compose
p
How to create ImageBitmap by array with points and colors? I have FloatArray every 3 items in it is the point info (x, y, color). Need to make ImageBitmap from it.
c
Ah you edited your question and now it is different. I’m not aware of something that creates a Bitmap from the format of data you have. (But it’s possible such a thing exists.) So I think you need to transform/flatten the data into a format you can pass to
createBitmap()
p
Thanks, Chris! I'll tranform it to match arguments of function you suggest.
l
Be careful how you map it. If it’s anything more than a small icon, that’s not going to be a fast process on the CPU. You may want to look at passing it to C or Kotlin/Native to use the GPU.
s
I wonder how that could look like? I've never seen it be done, especially by also using K/N
l
What is the source of the pixel data? Does it come from a library? If you can get it in int form, you could use libswscale or something.
c
There’s no need to pass this to a lower level. If you have hundreds of thousands or millions of pixels, just pass it to a worker thread to process.
It’s a static image after all, not animated, or video for example
l
If that's acceptable in this case, you can do that. It could take a non-negligible time.
c
I’m assuming he doesn’t need the image quickly. Otherwise why would it be provided in this format? (But I might be wrong.)
p
Thanks, friends! The reason for generation bitmap was that when using canvas it invokes onDraw for every change in ui even when non related elements changing. So i decided to generate bitmap manualy in LaunchedEffect and then apply it as Image. I didnt know about Canvas(ImageBitmap) that Eliezer use. Now I'll try his variant.
405 Views