Wednesday, 4 November 2020

Disable image anti-aliasing in Jetpack Compose

I need to disable anti-aliasing filter in Image to display pixel art properly. How can I do it?

I used to do it like in this answer:

val DRAW_FILTER = PaintFlagsDrawFilter(Paint.FILTER_BITMAP_FLAG, 0)

@SuppressLint("RestrictedApi")
class AliasingDrawableWrapper(wrapped: Drawable) : DrawableWrapper(wrapped) {
    override fun draw(canvas: Canvas) {
        val oldDrawFilter = canvas.drawFilter
        canvas.drawFilter = DRAW_FILTER
        super.draw(canvas)
        canvas.drawFilter = oldDrawFilter
    }
}

and

imageView.setImageDrawable(AliasingDrawableWrapper(drawable)


from Disable image anti-aliasing in Jetpack Compose

No comments:

Post a Comment