Status Update
Comments
so...@google.com <so...@google.com>
ma...@gmail.com <ma...@gmail.com> #3
Thanks for the report!
nj...@google.com <nj...@google.com> #4
The release notes documentation has been edited to clarify this change in behavior for line height.
To support non-standard text sizes, we encourage users to follow the Material design system and use a different style = LocalTextStyle.current.copy(lineHeight = TextUnit.Unspecified)
, or create a custom Typography
entirely.
ma...@gmail.com <ma...@gmail.com> #5
nj...@google.com <nj...@google.com> #6
In my case, I have multiple font sizes in the same Text
(using SpanStyle
in AnnotatedString
). There are legitimate reasons for this. For example, when combining Chinese and English (phonetic) together (for language-learning purposes).
ma...@gmail.com <ma...@gmail.com> #7
The resource is a 16x16 pixel art. I cannot have an higher resolution version. The resources are taken from a pixel art game because the app is a sort of companion for that game so it uses the same resources of the game.
ma...@gmail.com <ma...@gmail.com> #8
I cannot share a code snippet now but I've used the same approach exposed in that answer on Stack overflow
nj...@google.com <nj...@google.com> #9
Thanks for the screenshots.
I think you can do the following as a workaround to draw the pixel art image directly with anti-aliasing disabled:
val imageBitmap = BitmapFactory.decodeResource(
LocalContext.current.resources,
R.drawable.my_pixel_art
).asImageBitmap()
val paint = remember {
Paint().apply {
isAntiAlias = false
}
}
Canvas(modifier = Modifier.fillMaxSize()) { // DrawScope
drawIntoCanvas { canvas ->
canvas.drawImage(imageBitmap, Offset.Zero, paint)
}
}
ro...@google.com <ro...@google.com> #10
It's filtering you want to disable for pixel art, not anti-aliasing (although you may want that too when the image is rotated or uses subpixel positioning).
ma...@gmail.com <ma...@gmail.com> #11
I ended up using a custom Painter. The painter is almost identical to BitmapPainter
, I have overwritten only DrawScope.onDraw
private val customPaint = Paint().apply {
asFrameworkPaint().apply {
this.isDither = false
this.isFilterBitmap = false
this.isAntiAlias = false
}
}
override fun DrawScope.onDraw() {
drawIntoCanvas {
it.drawImageRect(
image = image,
srcSize = srcSize,
srcOffset = srcOffset,
dstSize = IntSize(
this@onDraw.size.width.roundToInt(),
this@onDraw.size.height.roundToInt()
),
paint = customPaint
)
}
}
ap...@google.com <ap...@google.com> #12
Branch: androidx-main
commit 5df92271b6eac729464aea71f9691acd21983777
Author: Nader Jawad <njawad@google.com>
Date: Tue Jul 13 12:35:20 2021
Add support for FilterQuality in DrawScope
Relnote: "Updated DrawScope#drawImage method that
consumes source and destination rects
to consume an optional FilterQuality
parameter. This is useful for pixel
art that is intended to be pixelated
when scaled up for pixel based art.
Updated BitmapPainter + Image composable
to also consume an optional FilterQuality
parameter"
Fixes: 180311607
Test: Added various tests to DrawScopeTest,
BitmapPainterTest and ImageTest
Change-Id: Ie4fb04013701add0fba1c5c6bb9da2812d6436e7
M compose/foundation/foundation/api/current.ignore
M compose/foundation/foundation/api/current.txt
M compose/foundation/foundation/api/public_plus_experimental_current.txt
M compose/foundation/foundation/api/restricted_current.ignore
M compose/foundation/foundation/api/restricted_current.txt
M compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ImageTest.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Image.kt
D compose/material/material/api/current.ignore
D compose/material/material/api/restricted_current.ignore
D compose/ui/ui-graphics/api/current.ignore
M compose/ui/ui-graphics/api/current.txt
M compose/ui/ui-graphics/api/public_plus_experimental_current.txt
D compose/ui/ui-graphics/api/restricted_current.ignore
M compose/ui/ui-graphics/api/restricted_current.txt
M compose/ui/ui-graphics/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/drawscope/DrawScopeTest.kt
M compose/ui/ui-graphics/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/painter/BitmapPainterTest.kt
M compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/Paint.kt
M compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/drawscope/CanvasDrawScope.kt
M compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope.kt
M compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/painter/BitmapPainter.kt
D compose/ui/ui-text/api/current.ignore
D compose/ui/ui-text/api/restricted_current.ignore
Description
Jetpack Compose release version: 1.0.0-alpha12
I would like to ask to allow to disable the antialiasing when using the
Image
composable. Paint has an antialiasing property but it's not exposed by the painter object used to draw the image.There is currently no easy way to disable the antialiasing without creating a custom painter and using a Paint object that is not the one passed to the DrawScope of the painter.
With SwiftUi I can simply use
func antialiased(Bool) -> Image
that is an extension ofImage