使用ImageView的变换矩阵,而不是canvas.scale(浮球,浮球,浮球,浮球) [英] Using an ImageView transform matrix instead of canvas.scale(float, float, float, float)

查看:204
本文介绍了使用ImageView的变换矩阵,而不是canvas.scale(浮球,浮球,浮球,浮球)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要改变的方式,我缩放和我的ImageView转向使用矩阵而不是调用 canvas.scale(,,,,),但我想不通出正确调用做到这一点。

I need to change the way I am scaling and moving my imageview to using a matrix instead of calling canvas.scale(,,,,), but I cannot figure out the proper calls to do this.

这在我的 ScaleListener 监听器类的 onScale

I had this in my ScaleListener listener class's onScale method

public boolean onScale(ScaleGestureDetector detector) {

    ...//determining zoom level and pivot points offset

    child.zoom(scaleFactor, zoomCenter[0], zoomCenter[1]);
}

在孩子的ImageView 的onDraw 方法:

I had in the child ImageView's onDraw method:

protected void onDraw(Canvas canvas){

    super.onDraw(canvas);
    canvas.scale(mScaleFactor, mScaleFactor, mPosX, mPosY);
    ...
    //do all the drawing here
}

public void zoom(float scaleFactor, float zoomCenterX, float zoomCenterY) {
    mScaleFactor = scaleFactor;
    mPosX = zoomCenterX;
    mPosY = zoomCenterY;

    //redraw and remeasure the mapview after zooming in
    invalidate();

}

我想在 onScale 方法是这样的:

public boolean onScale(ScaleGestureDetector detector) {
        ...//calculating scale and offsets

        Matrix m = child.getImageMatrix();
        m.reset();
        m.postScale(scaleFactor, scaleFactor);
        m.postTranslate(zoomCenter[0], zoomCenter[1]);
        child.setScaleType(ScaleType.MATRIX);
        child.setImageMatrix(m);

        child.invalidate();


        return true;
    }

但是,这似乎并没有做任何事......我在这里失去了一些东西?我试着用 child.getMatrix()来代替,但通过一个IllegalStateException称矩阵不能修改。任何帮助将是巨大的!

But this does not appear to be doing anything...am I missing something here? I tried using child.getMatrix() instead but that through an IllegalStateException saying the matrix cannot be modified. Any help would be great!

推荐答案

好吧,我想通了什么问题了。我使用 setImageMatrix(M)来应用到整个ImageView的子类,而不是设置的矩阵画布,像这样的:

Okay I figured out what the problem was. I was using setImageMatrix(m) to apply to the entire ImageView child class, instead of setting the matrix for the canvas, like this:

@Override
protected void onDraw(Canvas canvas){

    ...
    canvas.concat(transform);

}

我不知道有什么区别,两者之间虽然,如果有人知道看<一个href=\"http://stackoverflow.com/questions/18408401/what-is-the-difference-between-view-getmatrix-and-imageview-getimagematrix\">difference bewteen imageMatrix和基质

I'm not sure what the difference is between the two though, if anyone knows see difference bewteen imageMatrix and matrix

修改:使用 canvas.setMatrix(变换)搞砸滚动; canvas.concat(变换)建议,而不是和做这一招

EDIT: using canvas.setMatrix(transform) messed up the scrolling; canvas.concat(transform) was recommended instead and that does this trick

这篇关于使用ImageView的变换矩阵,而不是canvas.scale(浮球,浮球,浮球,浮球)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆