Alex Styl
05/25/2024, 10:43 AMModifier.scale()
on an Image() that has an ImageVector but the vector is really blurry (should be ultra crisp).
Is this a bug or am i doing something wrong? Code in 🧵Alex Styl
05/25/2024, 10:43 AMfun main() = singleWindowApplication {
Box(Modifier.scale(4f).fillMaxSize(), contentAlignment = Alignment.Center) {
Image(Add, null)
}
}
Image Vector:
val Add: ImageVector by lazy {
ImageVector.Builder(name = "add", defaultWidth = 40.0.dp, defaultHeight = 40.0.dp, viewportWidth = 40.0f, viewportHeight = 40.0f).apply {
path(fill = SolidColor(Color(0xFF212121)), fillAlpha = 1f, stroke = null, strokeAlpha = 1f, strokeLineWidth = 1.0f, strokeLineCap = StrokeCap.Butt, strokeLineJoin = StrokeJoin.Miter, strokeLineMiter = 1f, pathFillType = PathFillType.NonZero) {
moveTo(20f, 31.458f)
quadToRelative(-0.542f, 0f, -0.917f, -0.396f)
quadToRelative(-0.375f, -0.395f, -0.375f, -0.937f)
verticalLineToRelative(-8.833f)
horizontalLineTo(9.875f)
quadToRelative(-0.583f, 0f, -0.958f, -0.375f)
reflectiveQuadTo(8.542f, 20f)
quadToRelative(0f, -0.583f, 0.375f, -0.958f)
reflectiveQuadToRelative(0.958f, -0.375f)
horizontalLineToRelative(8.833f)
verticalLineTo(9.833f)
quadToRelative(0f, -0.541f, 0.375f, -0.916f)
reflectiveQuadTo(20f, 8.542f)
quadToRelative(0.542f, 0f, 0.938f, 0.375f)
quadToRelative(0.395f, 0.375f, 0.395f, 0.916f)
verticalLineToRelative(8.834f)
horizontalLineToRelative(8.792f)
quadToRelative(0.583f, 0f, 0.958f, 0.395f)
quadToRelative(0.375f, 0.396f, 0.375f, 0.938f)
quadToRelative(0f, 0.542f, -0.375f, 0.917f)
reflectiveQuadToRelative(-0.958f, 0.375f)
horizontalLineToRelative(-8.792f)
verticalLineToRelative(8.833f)
quadToRelative(0f, 0.542f, -0.395f, 0.937f)
quadToRelative(-0.396f, 0.396f, -0.938f, 0.396f)
close()
}
}.build()
}
Alex Styl
05/25/2024, 10:44 AMSpoudel347
05/25/2024, 10:45 AMAlex Styl
05/25/2024, 10:47 AMSpoudel347
05/25/2024, 10:49 AMAlex Styl
05/25/2024, 10:51 AMAlex Styl
05/25/2024, 10:56 AMModifier.scale()
to the preview composable. the contents of it are dynamicAlex Styl
05/25/2024, 10:58 AMAlex Styl
05/25/2024, 10:58 AMfun main() = singleWindowApplication {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Row {
Image(Add, null, Modifier.scale(1f))
Spacer(Modifier.width(40.dp))
Image(Add, null, Modifier.scale(4f))
}
}
}
Spoudel347
05/25/2024, 10:58 AMSpoudel347
05/25/2024, 10:59 AMAlex Styl
05/25/2024, 11:00 AMSpoudel347
05/25/2024, 11:02 AMSpoudel347
05/25/2024, 11:03 AMSpoudel347
05/25/2024, 11:03 AMAlex Styl
05/25/2024, 11:06 AMAlex Styl
05/25/2024, 11:06 AMSpoudel347
05/25/2024, 11:07 AMChrimaeon
05/25/2024, 11:07 AMChrimaeon
05/25/2024, 11:08 AMsize
.Spoudel347
05/25/2024, 11:08 AMAlex Styl
05/25/2024, 11:09 AMAlex Styl
05/25/2024, 11:09 AMChrimaeon
05/25/2024, 11:09 AMChrimaeon
05/25/2024, 11:10 AMAlex Styl
05/25/2024, 11:12 AMChrimaeon
05/25/2024, 11:13 AMImage
composable takes the vector infomation and creates a bitmap out of it.efemoney
05/25/2024, 11:38 AM.dp
for setting the sizes within the image components then it should just work ™️efemoney
05/25/2024, 11:41 AMHristijan
05/25/2024, 12:50 PM.size
and then increase/decrease that size, you're using a vector as others have described, the scale modifier is like a zoom, the more you scale the blurrier it'll get
Scale does scale the image within the bounds
Hope it's more clearAlex Styl
05/25/2024, 1:43 PMscale()
modifier that doesn't scale the vector. the way image works internally sounds like an implementation detail to me.
The same scenario using html + css is trivial to achieveChrimaeon
05/25/2024, 2:12 PMAlex Styl
05/25/2024, 2:22 PMChrimaeon
05/25/2024, 2:26 PMAlbert Chang
05/25/2024, 2:33 PMscale
is a parameter of the Image
, it may work like you want, but it’s instead an independent modifier and is transparent to the element it modifies.Alexander Maryanovsky
05/25/2024, 2:33 PMAlexander Maryanovsky
05/25/2024, 2:34 PMAlexander Maryanovsky
05/25/2024, 2:39 PMSpoudel347
05/25/2024, 2:41 PMAlex Styl
05/25/2024, 3:34 PMCompositionLocalProvider(LocalDensity provides Density(40f)) { }
and the scaled()
vector is crisp 👌
@Alexander Maryanovsky I have never opened an issue to Google's issue tracker. is it this one https://issuetracker.google.com/issues?q=status:open%20componentid:856989&s=created_time:desc?Alexander Maryanovsky
05/25/2024, 3:35 PMAlexander Maryanovsky
05/25/2024, 3:36 PMefemoney
05/25/2024, 3:39 PMGive the image an initial size as a state usingI dont think they had access to the inner component (maybe the child composable set the image size internally). He mentions this is functionality at the parent level. Which is why I suggested manipulating LocalDensity.and then increase/decrease that size,.size
I see aThis makes sense but bear in mind there is nothing in the public API of scale modifier, vectors or image composable that suggests it will work in the way you wanted so the argument can be made that it is rightly not supported because undocumented Anyways glad you got it working with LocalDensity 👍🏾modifier that doesn’t scale the vectorscale()
Alex Styl
05/25/2024, 4:08 PMAlex Styl
05/25/2024, 4:08 PMefemoney
05/25/2024, 4:10 PMLocalDensity
is what is used to resolve “density-independent pixel (dp)” units, eg. as long as you use 24.dp
for icon size, the final pixel value of that 24 will depend on the density, say if the pixel density was 3, then those 24dp will amount to 72 actual device pixels. Updating the density updates the amounts of raw pixels per dp.Sergey Y.
05/25/2024, 4:40 PMSergey Y.
05/25/2024, 4:43 PMAlbert Chang
05/25/2024, 4:53 PMImage(
Icons.Default.Close,
contentDescription = null,
modifier = Modifier
.size(50.dp)
.wrapContentSize()
.scale(10f)
.size(5.dp),
)
Alexander Maryanovsky
05/25/2024, 5:06 PMAlbert Chang
05/25/2024, 5:26 PMBox(
contentAlignment = Alignment.Center,
modifier = Modifier.size(50.dp)
) {
Image(
...,
modifier = Modifier
.scale(10f)
.size(5.dp),
)
}
Sergey Y.
05/25/2024, 6:03 PM