如何用Java遮罩球(圆)上的图像?

时间:2019-01-14 01:19:23

标签: java android

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

    mSurfaceWidth = width;
    mSurfaceHeight = height;
    mBallX = width / 2;
    mBallY = height/(1.1f);
    mVX = 0;
    mVY = 0;
}

private void drawCanvas() {
        Canvas c = mHolder.lockCanvas();
        c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        c.drawCircle(mBallX, mBallY, RADIUS, paint);
        mHolder.unlockCanvasAndPost(c);
    }

我想更改paint中的c.drawCircle()以使用我的图像。 我应该写什么代码?

1 个答案:

答案 0 :(得分:0)

尝试

private void drawCanvas() {
    Canvas c = mHolder.lockCanvas();
    c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);

    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.imagenamefromdrawableRes);
    c.drawBitmap(bmp, mBallX, mBallY - RADIUS, null);
    //c.drawCircle(mBallX, mBallY, RADIUS, paint);
    mHolder.unlockCanvasAndPost(c);
}