2016-04-07 29 views
1

你好我試圖放大在我的ImageView與此代碼的圖像上的特定點:變焦ImageView的矩陣

private void calculateAndZoom() { 

    matrix.set(getImageMatrix()); 
    printMatrixValues(getImageMatrix()); 

    float startpointY = (start_y_rel/ template_y_rel) * getHeight() * scale; 
    float startpointX = (start_x_rel/template_x_rel)* getWidth() * scale; 

    PrintDevMessage.print("Width: " + getWidth() + " Height: " + getHeight()); 

    matrix.setScale(1,1,0,0); 
    matrix.postScale(scale, scale, startpointX, startpointY); 

    this.setScaleType(ImageView.ScaleType.MATRIX); 
    this.setImageMatrix(matrix); 

    printMatrixValues(getImageMatrix()); 
} 

start_y_rel和start_x_rel相對於template_y_rel點和template_x_rel

我正在使用matrix.setScale(1,1,0,0)刪除任何以前的縮放並移動到第一個位置。

此代碼適用於比例尺3,但當我嘗試另一比例時,它會放大錯誤的位置。

回答

0

確定,所以後頭刮3天,我發現瞭解決方案:

private void calculateAndZoom() { 

    float cScale=getMatrixValue(getImageMatrix(),Matrix.MSCALE_X); 

    float newScale = ((float)1.0/cScale)*scale; 

    matrix.set(getImageMatrix()); 
    printMatrixValues(matrix); 

    float startpointY = ((start_y_rel/template_y_rel) * getHeight()); 
    float startpointX = ((start_x_rel/template_x_rel) * getWidth()); 

    PrintDevMessage.print("Width: " + getWidth() + " Height: " + getHeight()); 

    matrix.postScale(newScale, newScale, startpointX, startpointY); 

    this.setScaleType(ImageView.ScaleType.MATRIX); 
    this.setImageMatrix(matrix); 

    printMatrixValues(getImageMatrix()); 

} 

我沒有考慮圖像是大於屏幕並放置在imageview的當標尺被改變。所以我不得不重新計算我想要的舊比例尺像這樣:

float newScale = ((float)1.0/cScale)*scale;