3

このPhotoViewライブラリをカスタムImageViewに使用しました。特定のポイントで画像を拡大したいここで私が見つけた方法がある私はfocalXfocalYの値を渡すことができるか疑問に思ってsetScale(float scale, float focalX, float focalY, boolean animate)ImageViewで特定のXY座標(ポイント)をズームする方法

ですが、私はXとYは、私は現在渡していた座標持っており、それは非常に異なる位置にスケールします。ここで

は、指定されたスケールに

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

'focalX'と、私はこれをチェックしましたが、私の元のXY位置が遠くビューの左上からである' focalY'はあなたのビューの左上隅からの相対オフセットです – pskink

+0

@pskinkそれが拡大縮小している間のコーナー。 – Kuls

+0

0、0を渡すと、ビューの左上隅でスケーリングが行われます。getWidth()/ 2、getHeight()/ 2の場合、ビューの中心などでスケーリングが行われます。 – pskink

答えて

1

ImageViewで特定のXY座標をズームするには、scaleXとfocalYの値をscale(PhotoViewの最大スケールと最小スケールの間にある必要があります)とブール値の値を渡してアニメーションを設定します。最大 - 最小スケールを取得する

コード:それは、画面上の任意のポイントすることができ

mPhotoView.getMinimumScale(); 

mPhotoView.getMaximumScale(); 

focalXとfocalYを、ここで私は1つが、画面の中央部であり、他の左上隅で2つの例をとっています。両方の場合のコードは以下のとおりです。

コード:

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

希望します。ハッピーコーディング。

関連する問題