Search code examples
androidimagecanvaspaintantialiasing

How to enable android antialiasing in java canvas?


we had problems to draw nice & smooth images in java, because they were jagged. This code solved our problem:

g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

but now we are making the same app for android, but we have no clue how to apply similar interpolation or antialiasing to an android app.

(we use eclipse emulator)


Solution

  • Use a Paint object.

    1. create a Paint object p

    2. set p.setFilterBitmap(true)

    3. pass the paint p in your Canvas's draw methods

    This will activate (bilinear) filtering that will smoothen the "content" of the bitmap. You can also try to activate anti-aliasing with Paint.setAntiAlias(true), but that will affect only the outer edges of the bitmap (it is pretty handy for text though).