如何在Java canvas中启用android antialiasing? [英] How to enable android antialiasing in java canvas?

查看:69
本文介绍了如何在Java canvas中启用android antialiasing?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在绘制漂亮的图片时遇到了问题在Java中平滑图像,因为它们是锯齿状的.这段代码解决了我们的问题:

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);

但是现在我们正在为android开发相同的应用程序,但是我们不知道如何将相似的插值或抗锯齿应用于android应用程序.

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.

(我们使用eclipse仿真器)

(we use eclipse emulator)

推荐答案

使用 Paint 对象.

  1. 创建一个 Paint 对象 p

设置 p.setFilterBitmap(true)

在您的画布的绘制方法中传递油漆 p

pass the paint p in your Canvas's draw methods

这将激活(双线性)过滤,以平滑位图的内容".您也可以尝试使用 Paint.setAntiAlias(true)激活抗锯齿功能,但这只会影响位图的外边缘(尽管对于文本来说非常方便).

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).

这篇关于如何在Java canvas中启用android antialiasing?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆