Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have PathGeometry that draws a shape in wpf. I would like to keep the original shape and get a flipped copy of it.

What I have tried:

I found this solution for flipping images, but I don't know how to apply it in case of PathGeometry.
img.RenderTransformOrigin = new Point(0.5,0.5);
ScaleTransform flipTrans = new ScaleTransform();
flipTrans.ScaleX = -1;
//flipTrans.ScaleY = -1;
img.RenderTransform = flipTrans;
Posted
Updated 27-Apr-19 13:31pm

1 solution

The following method should provide you with a flipped PathGeometry. Just put it anywhere in your class, and pass it the PathGeometry you want to flip.
C#
public static PathGeometry FlipPG(PathGeometry src)
   {
   PathGeometry dst = src.Clone();  // Create a new, cloned, PathGeometry. 
                                    //   Depending on use case, might consider
                                    //   .CloneCore(), .CloneCurrentValue() or
                                    //   .CloneCurrentValueCore() methods 
                                    //   instead.
   ScaleTransform flipTrans = new ScaleTransform()
      {
      ScaleX = -1,
      CenterX = 0.5,           // Check CenterX and CenterY values, might not be
      CenterY = 0.5            //   adequate for your geometry.
      };
   dst.Transform = flipTrans;  // If there are other transforms already applied
                               //   to the original PathGeometry, this must be
                               //   added to a TransformCollection together with
                               //   the preexisting transforms.

   return dst;
   }

This is done in two steps, according to what you need to do:
- Create a copy of the original PathGeometry
- Flip it by applying a transform

Hope it helps. Regards!!

AFP
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900