canvas.getClipBounds()。左边是0总是在android中缩放画布时

时间:2015-07-12 17:19:50

标签: android canvas

将Canvas缩放后的值为

canvas.getClipBounds()。left始终为0

canvas.getClipBounds()。top始终为0

这些值在缩放时永远不会改变。是否有任何错误的实现?

Rect clipBounds = new Rect();
int canvasLeft;

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

    clipBounds = canvas.getClipBounds();
    canvas.save();

    canvasLeft = canvas.getClipBounds().left;

    if(scaleGestureDetector.isInProgress()){
        scaleGestureFocusX = this.scaleGestureDetector.getFocusX();
        scaleGestureFocusY = this.scaleGestureDetector.getFocusY();
        canvas.scale(this.scaleFactor, this.scaleFactor, scaleGestureFocusX, scaleGestureFocusY);
    }
    else{

        canvas.scale(this.scaleFactor, this.scaleFactor, scaleGestureFocusX, scaleGestureFocusY);
    }

    canvas.drawBitmap(bitmap, 0, 0, null);
    canvas.drawPath(path, paint);       
    canvas.restore();

}

1 个答案:

答案 0 :(得分:2)

你正在canvas.save()之后调用canvas.getClipBounds()。left。这就是为什么每次返回0 因为新生成的画布剪辑绑定后总是为0。

解决方案:首先调用 canvas.getClipBounds()。left ,然后调用 canvas.save()