我有一个自定义视图,它在 onDraw() 的画布上绘制一些位图。绘图正在工作。看代码片段:
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.save();
if(appInitialized) {
hsSide.draw(canvas);
scaleA.draw(canvas);
scaleB.draw(canvas);
}
canvas.scale(mScaleFactor, mScaleFactor, pivotX, pivotY);
canvas.restore();
}
我已经实现了一个 ScaleGestureListener,它在屏幕上应用捏缩放时缩放画布。问题是画布没有缩放。如果我在它canvas.scale(mScaleFactor, mScaleFactor, pivotX, pivotY);
之前if(appInitialized) {
缩放画布但在它之后绘制即hsSide.draw(canvas);
不缩放。它按正常比例绘制。以下是绘制方法:
hsDide.draw:
@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
canvas.drawBitmap(mBitmap, canvas.getWidth()/2 - mBitmap.getWidth()/2, 0, null);
}
scaleA.draw:
@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
canvas.drawBitmap(mBitmap, canvas.getWidth()/2 - mBitmap.getWidth()/2, canvas.getHeight()/2 - mBitmap.getHeight()/2, null);
}
scaleB.draw:
@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
canvas.save();
mMatrix.setRotate(currentAngle, canvas.getWidth()/2, canvas.getHeight()/2);
canvas.setMatrix(mMatrix);
canvas.drawBitmap(mBitmap, canvas.getWidth()/2 - mBitmap.getWidth()/2, canvas.getHeight()/2 - mBitmap.getHeight()/2, null);
canvas.restore();
}
知道我哪里出错了......???