本文介绍了如何在WPF中翻转pathgeometry?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在wpf中绘制形状的PathGeometry。我想保留原来的形状,并获得它的翻转副本。



我尝试过:



我发现这个翻转图像的解决方案,但我不知道如何在PathGeometry的情况下应用它。

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;

推荐答案

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;
   }



根据您的需要,这分两步完成:

- 创建原始副本PathGeometry

- 通过应用转换来翻转它



希望它有所帮助。问候!!



AFP


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


这篇关于如何在WPF中翻转pathgeometry?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 21:14