Skip to content

Instantly share code, notes, and snippets.

@dniHze
Created September 29, 2022 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dniHze/ab510b9ac2f352fddc5fa3ba14eeda2e to your computer and use it in GitHub Desktop.
Save dniHze/ab510b9ac2f352fddc5fa3ba14eeda2e to your computer and use it in GitHub Desktop.
Create painter with adjustable FilterQuality
@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