Android 画布.比例(比例,比例,x,y)

Android 画布.比例(比例,比例,x,y),android,canvas,view,Android,Canvas,View,我需要缩放图像。但问题是,如果我用不同的x,y点缩放秒时间,图像会向左或向右跳跃 我需要在点x,y->画布上缩放(缩放,缩放,x,y);不在点0,0->canvas.scale(缩放,缩放) 有人能帮我吗 Thanx要获得帮助,Bobert这里有一个名为Matrix.setRectRect(RectF,RectF,ScaleToFit)的方便方法来帮助您 Matrix imageMatrix = imageView.getImageMatrix(); RectF drawableRect = n

我需要缩放图像。但问题是,如果我用不同的x,y点缩放秒时间,图像会向左或向右跳跃

我需要在点x,y->画布上缩放(缩放,缩放,x,y);不在点0,0->canvas.scale(缩放,缩放)

有人能帮我吗


Thanx要获得帮助,Bobert

这里有一个名为Matrix.setRectRect(RectF,RectF,ScaleToFit)的方便方法来帮助您

Matrix imageMatrix = imageView.getImageMatrix();
RectF drawableRect = new RectF(0, 0, imageWidth, imageHeight);
RectF viewRect = new RectF(0, 0, imageView.getWidth(), imageView.getHeight());
imageMatrix.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER);
imageView.setImageMatrix(m);
这应该将矩阵imageMatrix设置为具有缩放和平移值的组合,这是显示ImageView小部件中居中且适合的可绘制图形所需的值

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.save();
    canvas.setMatrix(imageMatrix);
    ((BitmapDrawable)mIcon).draw(canvas);
    canvas.restore();
}

Thanx,但我不知道你的意思。我不使用drawable,位图中没有getImageMatrix()。
@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.save();
    canvas.setMatrix(imageMatrix);
    ((BitmapDrawable)mIcon).draw(canvas);
    canvas.restore();
}