Android:如何按体积填充位图颜色?

发布于 2024-12-06 01:04:48 字数 118 浏览 2 评论 0原文

我有一个不规则形状的位图图像,我用某种颜色填充它来模拟某种“米”。我当前的方法使用 ColorMatrixColorFilter 来替换原始 bimtap 上的颜色,最多可达位图高度的百分比。我真正想做的是按体积替换颜色。

I have a bitmap image that is of irregular shape that I fill with a certain color to simulate a "meter" of sorts. My current method uses a ColorMatrixColorFilter to replace color on the original bimtap, up to a percentage by bitmap height. What I'd really like to do is replace the color by volume.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最初的梦 2024-12-13 01:04:48

您可以在未填充的位图之上绘制一个填充的位图,但使用基于仪表级别的剪切路径。如果可以使用矩形剪辑来完成此操作,则使用 Canvas.clipRect(float,float,float,float) 将非常简单。否则,您可能必须指定更通用的路径并使用 Canvas.clipPath(Path)。然而,clipPath 没有抗锯齿,所以它看起来有点糟糕。

另一种选择是直接使用自定义路径绘制叠加层,为了方便起见,可能使用 SVG 路径基元。请参阅此项目:http://code.google.com/p/svg-android/ 特别是这个方法:http://svg-android.googlecode.com/svn/trunk/svgandroid/docs/com/larvalabs/svgandroid/SVGParser.html#parsePath(java.lang.String)。

You could draw a filled bitmap overtop of the unfilled one, but use a clipping path based on the meter's level. If that can be done with a rectangular clip, it will be quite straightforward with Canvas.clipRect(float,float,float,float). Otherwise, you may have to specify a more general path and use Canvas.clipPath(Path). However, the clipPath is not anti-aliased, so it can look a bit lousy.

Another option is to draw the overlay directly with a custom Path, possibly using SVG path primitives for convenience. See this project: http://code.google.com/p/svg-android/ and specifically this method: http://svg-android.googlecode.com/svn/trunk/svgandroid/docs/com/larvalabs/svgandroid/SVGParser.html#parsePath(java.lang.String).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文