gpt4 book ai didi

c# - 如何将 BitmapSource 旋转任意角度?

转载 作者:行者123 更新时间:2023-11-30 18:39:42 24 4
gpt4 key购买 nike

我如何创建一个 BitmapSource d,它是 BitmapSource s 旋转任意角度 a 的内容? 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"

最佳答案

我在 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 是一个图像。

关于c# - 如何将 BitmapSource 旋转任意角度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9321889/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com