Status Update
Comments
so...@google.com <so...@google.com>
nj...@google.com <nj...@google.com> #2
Branch: androidx-main
commit 9082f62682f853ad5251a1c79dde9eccba7abdd9
Author: Max Alfonso-Ying <maxying@google.com>
Date: Thu Apr 18 00:34:40 2024
[M2 text field] Apply background to decoration box
...instead of to the BasicTextField, so changing the
backgroundColor will properly change the decoration
box's background color.
Fixes:
Test: added unit tests
Relnote: "Fix backgroundColor not applying to
TextFieldDecorationBox and OutlinedTextFieldDecorationBox.
Decoration boxes now accept a `shape` parameter."
Change-Id: I371c26718597cb36ac537e9412ce476532afb40d
M compose/material/material/api/current.txt
M compose/material/material/api/restricted_current.txt
M compose/material/material/integration-tests/material-demos/src/main/java/androidx/compose/material/demos/TextFieldDecorationBoxDemos.kt
M compose/material/material/src/androidInstrumentedTest/kotlin/androidx/compose/material/textfield/TextFieldDecorationBoxTest.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/OutlinedTextField.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextField.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextFieldDefaults.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextFieldImpl.kt
ma...@gmail.com <ma...@gmail.com> #3
I'm creating an app that uses a lot of pixel art images. Which is the best way to draw them with the antialiasing disabled?
nj...@google.com <nj...@google.com> #4
I think we would need to understand what the expected result is vs the actual result that you are seeing with the existing behavior. This would give us a better sense of the root cause and help determine a solution to the desired effect. Could you go into more detail as to why drawing without anti-aliasing is necessary?
ma...@gmail.com <ma...@gmail.com> #5
Here are 2 screenshots of the same pixel art asset displayed in an android app using an ImageView. In the first screenshot(Screenshot_1566295198-576x1024.png) I've created a Bitmap with antialiasing, dither and filter disabled. I didn't find a way to get that result with compose
nj...@google.com <nj...@google.com> #6
Thanks! Can you share the code for these snippets as well?
From the screenshots it looks like you may need to have a higher resolution image per resource drawable buckets as well. Would you happen to know the display density of the Android device that this is running on?
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