我试图手动获取图像视图内部的图像并适合屏幕.我需要用矩阵来做(我稍后会动态地改变矩阵变换).
问题是我无法将图像置于视图中心(比例尺是合适的).这是代码:
// Compute the scale to choose (this works)
float scaleX = (float) displayWidth / (float) imageWidth;
float scaleY = (float) displayHeight / (float) imageHeight;
float minScale = Math.min(scaleX, scaleY);
// tx, ty should be the translation to take the image back to the screen center
float tx = Math.max(0,
0.5f * ((float) displayWidth - (minScale * imageWidth)));
float ty = Math.max(0,
0.5f * ((float) displayHeight - (minScale * imageHeight)));
// Compute the matrix
Matrix m = new Matrix(); …Run Code Online (Sandbox Code Playgroud)