0
我需要縮放圖像。但問題是,如果我用偏移x縮放secunde時間,y指向圖像向左或向右跳。我需要在點x,y - > canvas.scale(scale,scale,x,y)上縮放;不在0,0點 - > canvas.scale(scale,scale);canvas.scale(scale,scale,x,y)
public class Img extends View {
private Paint paint;
private Rect imgRect;
private Bitmap img;
private int h, w;
private int x, y;
private float scale = 1f;
private int scaleX, scaleY;
private int aScaleX, aScaleY;
public img(Context context) {
super(context);
paint = new Paint();
img = BitmapFactory.decodeResource(getResources(), R.drawable.uebersicht);
w = 1330;
h = 846;
imgRect = new Rect(0, 0, w, h);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.scale(scale, scale, scaleX, scaleY);
paint.setColor(Color.WHITE);
canvas.drawBitmap(img, null, imgRect, paint);
canvas.restore();
paint.setColor(Color.RED);
paint.setTextSize(30);
canvas.drawText(String.valueOf(scale), 10, 25, paint);
}
public void reDrawPos(int rX, int rY) {
x -= rX;
y -= rY;
calcImg();
invalidate();
}
public void reDrawScale(float s) {
scale = s;
calcImg();
invalidate();
}
private void calcImg() {
mapRect.set(x, y, x+w, y+h);
}
public float scaleSet(int sX, int sY) {
scaleX = sX;
scaleY = sY;
return scale;
}}
任何人都可以幫助我嗎?
thanx的幫助Bobert
Thanx,但我不知道你的意思。我不使用drawable,在位圖中是沒有getImageMatrix()。 – Bobert