如何将图像缩放到android中的指定坐标

sat*_*ish 11 android zooming imageview

我想将图像缩放到图像的特定部分(到指定的坐标).我有一个图像,我在全屏显示Android图像视图.当我点击一个按钮时,我想将图像缩放到图像的指定坐标.我说左边的坐标是左边:500,顶部:50,宽度:60,高度:20.我希望将完整图像缩放到指定的坐标,并将此子图像放在图像视图的中心.

目前我正在通过将图像裁剪为指定坐标来实现.我会得到一个小图像.我在图像视图中显示它.但我认为这不是一个好的解决方案.

有人可以帮我找到实现缩放功能的方法.

Rau*_*pan 0

也许这就是您正在寻找的:

/**
 * Set zoom to the specified scale. Image will be centered around the point
 * (focusX, focusY). These floats range from 0 to 1 and denote the focus point
 * as a fraction from the left and top of the view. For example, the top left 
 * corner of the image would be (0, 0). And the bottom right corner would be (1, 1).
 * @param scale
 * @param focusX
 * @param focusY
 * @param scaleType
 */
public void setZoom(float scale, float focusX, float focusY, ScaleType scaleType) {
    //
    // setZoom can be called before the image is on the screen, but at this point, 
    // image and view sizes have not yet been calculated in onMeasure. Thus, we should
    // delay calling setZoom until the view has been measured.
    //
    if (!onDrawReady) {
        delayedZoomVariables = new ZoomVariables(scale, focusX, focusY, scaleType);
        return;
    }

    if (scaleType != mScaleType) {
        setScaleType(scaleType);
    }
    resetZoom();
    scaleImage(scale, viewWidth / 2, viewHeight / 2, true);
    matrix.getValues(m);
    m[Matrix.MTRANS_X] = -((focusX * getImageWidth()) - (viewWidth * 0.5f));
    m[Matrix.MTRANS_Y] = -((focusY * getImageHeight()) - (viewHeight * 0.5f));
    matrix.setValues(m);
    fixTrans();
    setImageMatrix(matrix);
}
Run Code Online (Sandbox Code Playgroud)

更多信息您可以参考:

这个链接Github可以帮助你更多

在此输入链接描述

编辑 :

请参考这个你会得到答案:

您的问题的答案