how to flip Image in wpf

后端 未结 6 1122
时光说笑
时光说笑 2021-01-31 01:56

I recently learned how to rotate a BitmapImage using the \'TransformedBitmap\' and \'RotateTransformed\' classes. Now I am able to perform clockwise rotations on my images. But

6条回答
  •  暖寄归人
    2021-01-31 02:41

    Use a ScaleTransform with a ScaleX of -1 for horizontal and ScaleY of -1 for vertical flipping, applied to the image's RenderTransform property. Using RenderTransformOrigin="0.5,0.5" on the image makes sure your image gets flipped around its center, so you won't have to apply an additional TranslateTransform to move it into place:

    
      
        
      
    
    

    for horizontal flipping and

    
      
        
      
    
    

    for vertical.

    If you want to do it in code-behind, in C# it should look something like this:

    img.RenderTransformOrigin = new Point(0.5,0.5);
    ScaleTransform flipTrans = new ScaleTransform();
    flipTrans.ScaleX = -1;
    //flipTrans.ScaleY = -1;
    img.RenderTransform = flipTrans;
    

提交回复
热议问题