用9png在android中创建图像蒙版

时间:2015-10-08 07:46:27

标签: android imageview android-canvas mask

所以我有这个9png: enter image description here

我有这个形象: enter image description here

我需要达到以下目的: enter image description here

这是我能得到的最接近的: enter image description here

这就是我尝试这样做的方式:

public class CustomView extends ImageView {

private Bitmap mImage;
private Bitmap mMask;
private int mPosX = 0;
private int mPosY = 0;

private final Paint maskPaint;
private final Paint imagePaint;

public CustomView(Context context) {
    super(context);
    maskPaint = new Paint();
    maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

    imagePaint = new Paint();
    imagePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OVER));

    mImage = BitmapFactory.decodeResource(context.getResources(), R.drawable.dummy_video);
    mMask = BitmapFactory.decodeResource(context.getResources(), R.drawable.friend_bubble);
}

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.save();
    canvas.drawBitmap(mMask, 0, 0, maskPaint);
    canvas.drawBitmap(mImage, mPosX, mPosY, imagePaint);
    canvas.restore();
}

}

我的猜测是9png只是继续画画而且不知道何时停止。

有人可以帮忙吗? :)

0 个答案:

没有答案