Android Alpha Masking问题

时间:2011-05-26 18:32:37

标签: android animation alpha porter-duff

在我重写的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);



    }

似乎不起作用,任何人都有任何想法?

1 个答案:

答案 0 :(得分:2)

我能够使用xfermode DST_OUT方法

来做到这一点