Android:如何按体积填充位图颜色?
我有一个不规则形状的位图图像,我用某种颜色填充它来模拟某种“米”。我当前的方法使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在未填充的位图之上绘制一个填充的位图,但使用基于仪表级别的剪切路径。如果可以使用矩形剪辑来完成此操作,则使用 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).