Как повернуть BitmapSource на любой угол? - PullRequest
3 голосов
/ 17 февраля 2012

Как я могу создать BitmapSource d, который является содержимым BitmapSource s, повернутым на любой угол a?RotateTransform не подходит, поскольку он ограничен углами, кратными только 90 градусам.

EDIT: демонстрация ограничения 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 голосов
/ 17 февраля 2012

Я создал тестовый проект в 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 - это изображение.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...