Android 通过Matrix来对图片进行缩放,旋转和平移

private Matrix matrix;

public void scale(View view) {
    float s = Float.parseFloat(scale.getText().toString());
    matrix.postScale(s, s);
    //将 matrix 设置到 imageView
    img.setImageMatrix(matrix);

}
public void rotate(View view) {
    float degree = Float.parseFloat(rotate.getText().toString());
    matrix.postRotate(degree);
    img.setImageMatrix(matrix);
}
public void translate(View view) {
    float dx = Float.parseFloat(translate.getText().toString());
    float dy = Float.parseFloat(back.getText().toString());
    //保存平移数据
    matrix.postTranslate(dx, dy);
    img.setImageMatrix(matrix);
}
public void back(View view) {
    matrix.reset();
    img.setImageMatrix(matrix);
}


你可能感兴趣的:(Android)