图像缩放不合适

发布于 2024-12-26 02:21:19 字数 498 浏览 0 评论 0原文

我想捏缩放图像,但问题是当我缩放时,它不会从我手指所在的位置放大和缩小。它转到点 0, 0。

这是我的代码:

@Override
public boolean onScale(ScaleGestureDetector detector) {
    mScaleFactor = detector.getScaleFactor();

    Log.e("ScaleFactor", "" + mScaleFactor);

    // Don't let the object get too small or too large.
    mScaleFactor = Math.max(0.4f, Math.min(mScaleFactor, 5.0f));
    if(mScaleFactor>=1)
        mScaleFactor=1f;

    invalidate();
    return true;
}

我尝试了很多,但可以找到任何方法来解决这个问题。

I want to pinch zoom an image but problem is when I zoom it does not zoom in and out from where my fingers are. It goes to point 0, 0.

Here is my code:

@Override
public boolean onScale(ScaleGestureDetector detector) {
    mScaleFactor = detector.getScaleFactor();

    Log.e("ScaleFactor", "" + mScaleFactor);

    // Don't let the object get too small or too large.
    mScaleFactor = Math.max(0.4f, Math.min(mScaleFactor, 5.0f));
    if(mScaleFactor>=1)
        mScaleFactor=1f;

    invalidate();
    return true;
}

I tried a lot but could get any way to fix this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久光 2025-01-02 02:21:19

这很有用

private float[] matrixValues = new float[9];
private float maxZoom;
private float minZoom;
private float height;
private float width;
private RectF viewRect; 


private void init() {
    maxZoom = 4;
    minZoom = 0.25f;
    height = myimage.getDrawable().getIntrinsicHeight()+20;
    width = myimage.getDrawable().getIntrinsicWidth()+20;
    viewRect = new RectF(0, 0, myimage.getWidth()+20, myimage.getHeight()+20);
}

it is useful

private float[] matrixValues = new float[9];
private float maxZoom;
private float minZoom;
private float height;
private float width;
private RectF viewRect; 


private void init() {
    maxZoom = 4;
    minZoom = 0.25f;
    height = myimage.getDrawable().getIntrinsicHeight()+20;
    width = myimage.getDrawable().getIntrinsicWidth()+20;
    viewRect = new RectF(0, 0, myimage.getWidth()+20, myimage.getHeight()+20);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文