使用矩阵缩放 Imageview
Zoom Imageview using matrix
您好,我正在尝试使用以下代码放大图像视图中图像的特定点:
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;
您好,我正在尝试使用以下代码放大图像视图中图像的特定点:
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;