在WPF中旋转后如何使图像适合边框 [英] How to fit the image to to border after rotation in WPF

查看:137
本文介绍了在WPF中旋转后如何使图像适合边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个边框,里面有图像.在按钮上单击将图像旋转90度. 这是我的原图

I have one border inside which am having an image. on button click am rotating that image to 90 degrees. this is my original image

下面是旋转后

如您所愿,旋转后我的图像不适合边框.我需要它完全填补边界.这里缺少什么?

As you can after rotation my image doesn't fit into the border. I need it to be fill the border completely. What is am missing here?

推荐答案

我认为,您正在使用RenderTransform旋转图像.

I think, you are using RenderTransform to rotate the image.

相反,请使用LayoutTransform.

查看示例:

<StackPanel>
    <Border Width="500" Height="300" BorderBrush="Black" BorderThickness="1">
        <Image Source="sombrero.jpg" Stretch="Fill" x:Name="img" HorizontalAlignment="Center" VerticalAlignment="Center">
        </Image>
    </Border>
    
    <Button Content="Rotate" Click="ButtonBase_OnClick"></Button>
</StackPanel>

隐藏代码:

private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
        img.LayoutTransform = new RotateTransform(90);
    }

之前:

之后:

希望这会有所帮助.

这篇关于在WPF中旋转后如何使图像适合边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆