2014-11-06 88 views
0

我可以旋转图像:旋转和缩放图像刷

RotateTransform aRotateTransform = new RotateTransform(); 
    aRotateTransform.CenterX = 0.5; 
    aRotateTransform.CenterY = 0.5; 
    tateTransform.Angle = rotationAngle; 

    ImageBrush bgbrush = new ImageBrush(); 
    bgbrush.RelativeTransform = aRotateTransform; 

    ScaleTransform s = new ScaleTransform(); 
    s.ScaleX = -1; // how to set without overriding the rotation? 
    ... 

我如何扩展它除了?我尝试使用矩阵没有成功。

回答

2

你可以使用一个TransformGroup像这样:

TransformGroup tg = new Transformgroup(); 
tg.Children.Add(rotateTransform); 
tg.Children.Add(scaleTransform); 
bgbrush.RelativeTransform = tg; 
1

只是为了保持完整性。使用矩阵变换,你会通过这个得到预期的结果:

var transform = Matrix.Identity; 
transform.RotateAt(rotationAngle, 0.5, 0.5); 
transform.Scale(-1, 1); 

bgbrush.RelativeTransform = new MatrixTransform(transform); 

不过,我想,其实你要保持图像的中心,所以你可能会使用ScaleAt代替Scale

var transform = Matrix.Identity; 
transform.RotateAt(rotationAngle, 0.5, 0.5); 
transform.ScaleAt(-1, 1, 0.5, 0.5); 

bgBrush.RelativeTransform = new MatrixTransform(transform);