Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中屏蔽球(圆)上的图像?_Java_Android - Fatal编程技术网

如何在Java中屏蔽球(圆)上的图像?

如何在Java中屏蔽球(圆)上的图像?,java,android,Java,Android,我想更改c.drawCircle()中的paint以使用我的图像。 我应该写什么代码?试试这个 @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { mSurfaceWidth = width; mSurfaceHeight = height; mBallX = width / 2; mBallY = height/(1.1f

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

试试这个

@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);
    }

你想用想象代替黑色背景吗?是的!你知道怎么做吗?
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);
}