旋转bitmapimage [英] rotate a bitmapimage

查看:125
本文介绍了旋转bitmapimage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想旋转位图图像我写了一些代码并且它工作



I want to rotate a bitmap image I wrote some code and it work

TransformedBitmap TempImage = new TransformedBitmap();

 TempImage.BeginInit();
 TempImage.Source = MyImageSource; // MyImageSource of type BitmapImage

 RotateTransform transform = new RotateTransform(90);
 TempImage.Transform = transform;
 TempImage.EndInit();

 image1.Source = TempImage ;





但是我希望MyImageSource得到这个修改,因为就像那样如果我再次点击按钮没有任何事情发生,这个正常它得到我的图像的第一种形式,我也希望它采取这种形式,因为我必须在修改后保存它。



but I want that MyImageSource get this modification, because like that if I click again in the button nothing happen and this normal it get the first form of my image, and also I want it to take this form because I have to save it after modification.

推荐答案





您的问题是,每次旋转图像时,您正在使用图像存储它的旋转,因为它的图像旋转设置为90度它不再旋转它更简单解决。只需声明一个int来存储您的旋转角度,将其设置为0并在每次调用函数时添加90度。





Hi,

Your problem is that each time your rotate your image you are using you image store it's rotation as it's image rotation is set to 90 degrees it will not rotate any more it is rather simple to work around. Simply declare an int to store your rotation angle set it to 0 and add 90 degrees each time you call your function.


int Rotate_angle = 0;

private void Button_Click(object sender, RoutedEventArgs e)
{
        TransformedBitmap TempImage = new TransformedBitmap();
 
        TempImage.BeginInit();
        TempImage.Source = MyImageSource; // MyImageSource of type BitmapImage

        RotateTransform transform = new RotateTransform(Rotate_angle+=90);
        TempImage.Transform = transform;
        TempImage.EndInit();
 
        image1.Source = TempImage ;
}







如果你的图像显示在图像控件中,这是一个更简单的方法这样命名为img






A much simpler method if you have your Image displayed in an Image control named "img" like this

<grid>
    <stackpanel>
        <Image Name="img" Source="01.jpg"/>


        <Button Click="Button_Click" Content="CLICK"/>
    </stackpanel>
</grid>





将此作为您的代码背后;





is to put this as your code behind;

int Rotate_angle = 0;
private void Button_Click(object sender, RoutedEventArgs e)
{
        img.RenderTransformOrigin = new Point(0.5, 0.5);
        img.RenderTransform = new RotateTransform(Rotate_angle+=45);
}





此方法更清晰,允许您以不同角度旋转。



希望这会对你有所帮助

干杯

Chris



This method is cleaner and allows you to rotate by different angles.

Hope this helps you
Cheers
Chris


你可以试试这个。

http://social.msdn。 microsoft.com/Forums/en-US/csharpgeneral/thread/a1e62e03-d732-444d-bb3d-6e7907fd5e16/ [ ^ ]

这也是

.NET中的图像轮换 [ ^ ]
You may try this.
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/a1e62e03-d732-444d-bb3d-6e7907fd5e16/[^]
and this also
Image Rotation in .NET[^]


这篇关于旋转bitmapimage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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