0

I have a Image control rotate problem(WPF).

I have a 500px width & 300px height photo. when I place this photo in a Image control:

<window>
    <grid>
        <Border BorderBrush="Green" BorderThickness="4" Margin="20" VerticalAlignment="Center" HorizontalAlignment="Center">
            <Image Source="test.bmp"/>
        </Border>
    </grid>
</window>

It looks good, the border will auto-size itself depands on image's size: 500x300.

It looks good

Now I want to rotate the image 90 degree:

<window>
    <grid>
        <Border BorderBrush="Green" BorderThickness="4" Margin="20" VerticalAlignment="Center" HorizontalAlignment="Center">
            <Image Source="test.bmp" RenderTransformOrigin="0.5,0.5">
                <Image.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform Angle="90"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </Image.RenderTransform>
            </Image>
        </Border>
    </grid>
</window>

My thinking is, the border size will also change from 500x300 to 300x500.

but actually it's not - still 500x300, and the image control also hold 500x300 place.

Oh no

my problem is, how to fix this?

[UPDATE: SOLVED]

I used LayoutTransform instead of RenderTransform:

<window>
    <grid>
        <Border BorderBrush="Green" BorderThickness="4" Margin="20" VerticalAlignment="Center" HorizontalAlignment="Center">
            <Image Source="test.bmp" >
                <Image.LayoutTransform>
                    <RotateTransform Angle="90"/>
                </Image.LayoutTransform>
            </Image>
        </Border>
    </grid>
</window>

Solved

Oh My Dog
  • 781
  • 13
  • 32
  • You transformed the Image, and it gets transformed. You did not transform Border, it did'nt. Even if you transform the Border, it won't help unless you either transform your window or have your window so large that it handles the transformed image/border. What excactly do you want? – publicgk Aug 19 '15 at 04:41
  • @public gk, my border's size is depending on image's size, so if image rotated 90 degree, border's size must be the same. but you can see the last image, size's still 500x300. – Oh My Dog Aug 19 '15 at 05:41
  • I use LayoutTransform instead of RenderTransform, problem solved. – Oh My Dog Aug 19 '15 at 06:13
  • @OhMyDog If the problem is solved, you should either write an answer, or delete the question. – Clemens Aug 19 '15 at 06:56
  • @Clemens, I updated my post to keep the answer for other visitors, thanks. – Oh My Dog Aug 19 '15 at 08:23

0 Answers0