在Android的画布综合业务 [英] Composite operations in Android Canvas
问题描述
我刚开始与Android的发展,我从JavaScript / HTML世界未来,所以我目前正在调查Android SDK的准备。
I'm just starting with Android development and I'm coming from JavaScript/HTML world so I'm currently investigating the possibilities of the Android SDK.
在HTML 5画布支持复合操作(见这里)。
The HTML 5 canvas supports composite operations (See here).
这是可能在Android印刷品吗?我扫视了Canvas类的API,但找不到任何有用。我至少需要复合操作源式或(如果这是不可能的),源之上。
Is this possible in an Android Canvas? I scanned the API of the Canvas class but couldn't find anything useful. I need at least the composite operation "source-in" or (if this isn't possible) "source-atop".
推荐答案
成分是通过在画布
与油漆$拉丝处理C $ C>一个使用
PorterDuffXfermode
。
Composition is handled by drawing on a Canvas
with a Paint
that uses a PorterDuffXfermode
.
Paint p=new Paint();
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DARKEN));
canvas.drawBitmap(bitmap, 0, 0, p);
请参阅<一href="http://stackoverflow.com/questions/2763572/override-ondraw-to-change-how-the-drawing-occurs-android">here获取更多信息。我也设法覆盖的OnPaint
这样我们就可以该组合物适用于画themeselves元素。
See here for more info. I also managed to override onPaint
so that we can apply this composition to elements that draw themeselves.
这篇关于在Android的画布综合业务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!