I have some `ImageBitmap`s that I'm rendering into...
# compose
s
I have some `ImageBitmap`s that I'm rendering into a UI using
Image
. That works nicely, images appear in their natural size. However on higher density devices, images appear smaller. Is there any easy way to use the
LocalDensity
to render an image the same natural size independent of screen density? I've tried applying
Modifier.scale(LocalDensity.current.density)
and while the image seems to be rendered bigger on higher density devices, the size of the widget doesn't seem to increase, i.e. only part of the image is visible. I see that
Image
is using an
ImagePainter
under the hood, but I don't see an easy way to supply a target size for it. Any suggestions?
k
What defines the size of your widget? Do you have fixed
dp
width and height for it?
s
I don't think I'm setting any size for the Image widget or any of the widgets it is contained within (it's in an item of a LazyColumn), I don't know how exactly it does it but I think the Image Composable determines it's size from the pixel size of the ImageBitmap
my hunch is it has to do with the "intrinsic size"
k
That’s probably the case. Say you have a 200x200px image. So that definitely is going to take a smaller “physical” space on a higher density screen
Same as using
wrap_content
in the view world. You want to set fixed
dp
based dimensions for your image instead
s
thanks Kirill, that helps indeed