3

我已经使用这个PhotoView库自定义ImageView的。我想在特定点上缩放图像。下面是我找到的方法是setScale(float scale, float focalX, float focalY, boolean animate)如何在特定的XY坐标缩放(点)在ImageView的

我想知道我能传递的focalXfocalY的值,我有X和Y坐标我传递目前,它扩展到非常不同的位置。

这里是一个片段,

intResultX = intTotalX/intArraySize; 
intResultY = intTotalY/intArraySize; 
mMap.setScale(5, intResultX, intResultY, true); 
+0

'focalX'和'focalY'是从您的视图的左上角 – pskink

+0

@pskink相对偏移我检查了这一点,但我原来的XY位置是远离视图的左上角它缩小了一个角。 – Kuls

+0

如果你通过0,0的缩放是围绕你的意见左上角,如果你通过getWidth()/ 2,getHeight()/ 2缩放是围绕你的视图的中心等完成 – pskink

回答

1

要以特定的XY坐标放大在ImageView的可以带有刻度沿传递focalX和focalY的值(必须是最大规模的PhotoView的分钟刻度之间)和布尔值来设置动画。

代码来获取最大最小刻度:

mPhotoView.getMinimumScale(); 

mPhotoView.getMaximumScale(); 

focalX和focalY它可以在屏幕上任意点,在这里我已经采取了两个例子一个是屏幕的中心,另一种是左上角。以下是这两种情况的代码。

代码:

Random r = new Random(); 
float minScale = mPhotoView.getMinimumScale(); 
float maxScale = mPhotoView.getMaximumScale(); 
float randomScale = minScale + (r.nextFloat() * (maxScale - minScale)); 

DisplayMetrics displayMetrics = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); 
int height = displayMetrics.heightPixels; 
int width = displayMetrics.widthPixels; 
int centerX=width/2; 
int centerY =height/2; 

/*pass a value of focalX and focalY to scale image to center*/ 
//mPhotoView.setScale(randomScale, centerX, centerY, true); 

/*pass a value of focalX and focalY to scale image to top left corner*/ 
mPhotoView.setScale(randomScale, 0, 0, true); 
+0

但是如何缩放(缩放和移动)到位图的x,y坐标? https://stackoverflow.com/questions/48961771/how-to-scale-photoview-to-x-y-coordinates-of-bitmap – NickUnuchek

1

设置缩放到指定的规模。图像将围绕点 (focusX,focusY)为中心。这些浮标范围从0到1并且表示焦点 从视图的左侧和顶部的馏分。例如,左上 角的图像将是(0,0)。而右下角将是(1,1)。

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); 
} 

希望这会有所帮助。快乐的编码。