안녕하세요 저는이 코드를 사용하여 이미지 뷰의 이미지에서 특정 지점을 확대하려고합니다.
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에서 작동하지만 다른 스케일을 시도하면 잘못된 위치에서 확대됩니다.
좋아, 머리를 긁고 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;
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다