Android Alpha Masking问题
在我重写的 onDraw() 函数中,我有一个画布,里面有两个仪表(仪表是 PNG 的)。仪表堆叠在一起。我希望只显示顶部仪表的一半,同时显示另一半的底部仪表。到目前为止,这就是我所拥有的:
@Override
public void onDraw(Canvas c){
int targetWidth=200;
int targetHeight=200;
Paint p = new Paint();
Bitmap bottom = BitmapFactory.decodeResource(getResources(), R.drawable.dashboard_rpm_bottom);
Bitmap top = BitmapFactory.decodeResource(getResources(), R.drawable.dashboard_rpm_top);
p.setFilterBitmap(false);
c.translate(55,320);
c.drawBitmap(
bottom,
new Rect(0, 0, bottom.getWidth(), bottom.getHeight()),
new Rect(0, 0, targetWidth, targetHeight),
p);
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
c.drawBitmap(
top,
new Rect(0, 0, top.getWidth(), top.getHeight()),
new Rect(0, 0, targetWidth, targetHeight),
p);
}
似乎不起作用,有人有什么想法吗?
in my overridden onDraw() function i have a canvas with two gauges in it (gauges are PNG's). The gauges are stacked on top of eachother. I would like only half of the gauge on the top to show while revealing the bottom gauge on the other half. Here's what i have so far:
@Override
public void onDraw(Canvas c){
int targetWidth=200;
int targetHeight=200;
Paint p = new Paint();
Bitmap bottom = BitmapFactory.decodeResource(getResources(), R.drawable.dashboard_rpm_bottom);
Bitmap top = BitmapFactory.decodeResource(getResources(), R.drawable.dashboard_rpm_top);
p.setFilterBitmap(false);
c.translate(55,320);
c.drawBitmap(
bottom,
new Rect(0, 0, bottom.getWidth(), bottom.getHeight()),
new Rect(0, 0, targetWidth, targetHeight),
p);
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
c.drawBitmap(
top,
new Rect(0, 0, top.getWidth(), top.getHeight()),
new Rect(0, 0, targetWidth, targetHeight),
p);
}
doesn't seem to work, anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够使用 xfermode DST_OUT 方法来做到这一点
I was able to do this using the xfermode DST_OUT method