Stefan Oltmann
07/07/2021, 8:52 PMImage.makeFromEncoded() as well as Android contentResolver.loadThumbnail() give you a Bitmap , but Compose Image needs an ImageBitmap and as far as I can see the implementation of the extension asImageBitmap() is on both worlds a really expensive conversation. 😞
Why isn't there a way to directly load an ImageBitmap if that's the needed format? 🤔romainguy
07/07/2021, 8:54 PMBitmap inside an ImageBitmapromainguy
07/07/2021, 8:54 PMStefan Oltmann
07/07/2021, 9:04 PMtargetBitmap.getPixels(
buffer,
bufferOffset,
stride,
startX,
startY,
width,
height
)Stefan Oltmann
07/07/2021, 9:04 PMStefan Oltmann
07/07/2021, 9:04 PMval bytes = bitmap.readPixels(imageInfo, stride * bytesPerPixel.toLong(), startX, startY)!!
ByteBuffer.wrap(bytes)
.order(ByteOrder.LITTLE_ENDIAN) // to return ARGB
.asIntBuffer()
.get(buffer, bufferOffset, bytes.size / bytesPerPixel)Stefan Oltmann
07/07/2021, 9:05 PMStefan Oltmann
07/07/2021, 9:06 PMreadPixels() , the main method of that BitmapImage interface, happensStefan Oltmann
07/07/2021, 9:07 PMStefan Oltmann
07/07/2021, 9:12 PMPainter (the third possible argument beside ImageBitmap and ImageVector for a Compose Image) implementation that can draw a Bitmap directly without making that call to readPixels() that will create an extra array on every call.Stefan Oltmann
07/07/2021, 9:15 PMrememberGlidePainter() which I guess is a way around that.
Only that there is no such thing as Glide or Coil available for Compose for Desktop... or is it?Stefan Oltmann
07/07/2021, 9:16 PMromainguy
07/07/2021, 9:27 PMgetPixel() is only invoked from readPixels(), which is not used for renderingromainguy
07/07/2021, 9:28 PM