Created
September 29, 2022 12:42
-
-
Save dniHze/ab510b9ac2f352fddc5fa3ba14eeda2e to your computer and use it in GitHub Desktop.
Create painter with adjustable FilterQuality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
public fun painterResource( | |
@DrawableRes id: Int, | |
filterQuality: FilterQuality, | |
): Painter { | |
LocalConfiguration.current | |
val resources = LocalContext.current.resources | |
val value = remember { TypedValue() } | |
resources.getValue(id, value, true) | |
val path = value.string | |
return if (path?.endsWith(".xml") == true) { | |
painterResource(id = id) | |
} else { | |
val image = remember(path, id) { | |
ImageBitmap.imageResource(resources, id) | |
} | |
BitmapPainter( | |
image = image, | |
filterQuality = filterQuality, | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment