开发者

Android: How do you fill a bitmap with color by volume?

开发者 https://www.devze.com 2023-04-06 21:49 出处:网络
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 bim

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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消