如何以任何角度旋转BitmapSource?

时间:2012-02-17 01:55:46

标签: c# wpf

我如何创建一个BitmapSource d,它是BitmapSource以任意角度旋转的内容? RotateTransform不适合,因为它仅限于90度的倍数。

编辑:RotateTransform限制演示:

        // Create the TransformedBitmap to use as the Image source.
        TransformedBitmap tb = new TransformedBitmap();
        // Create the source to use as the tb source.
        BitmapImage bi = (BitmapImage)capture;
        // Properties must be set between BeginInit and EndInit calls.
        tb.BeginInit();
        tb.Source = bi;
        // Set image rotation.
            var transform = new System.Windows.Media.RotateTransform(angle:30);
        tb.Transform = transform;
        tb.EndInit();  // "Transform must be a combination of scales, flips, and 90 degree rotations"

1 个答案:

答案 0 :(得分:0)

我在Blend中创建了一个测试项目。 RotateTransform可以是任何角度:

<Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SampleDataSource}}">
    <Image Margin="0,0,191,122" Source="{Binding Property1}" RenderTransformOrigin="0.5,0.5">
        <Image.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform Angle="26.565"/>
                <TranslateTransform/>
            </TransformGroup>
        </Image.RenderTransform>
    </Image>
</Grid>

我创建了SampleDataSource,其中Property1是一个图像。