2014-11-06 90 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);