2

我正在根据我找到的示例使用稍微修改的调整大小代码。但是,在调整大小时,一切都被翻转了。我想要么把它翻转回来,要么首先防止它翻转。

这是我的调整大小代码:

private static void ResizePath(SKPath buildingPath, IEnumerable<Room> rooms)
{
    var info = new SKImageInfo(512, 600, SKImageInfo.PlatformColorType, SKAlphaType.Premul);
    var drawSpaceRect = SKRect.Create(info.Size);
    //I need to find the size of the path
    var buildingPathRect = buildingPath.TightBounds;
    //I want to find the largest rectangle that can fit on my canvas maintaining the path's aspect ratio
    var sketchRect = drawSpaceRect.AspectFit(buildingPathRect.Size);
    //Now I need to transform the path to draw within the sketchRect
    //First translate original path to its own origin
    var firstTranslateM = SKMatrix.MakeTranslation(-buildingPathRect.Left, -buildingPathRect.Top);
    //Next handle scaling.  Since I maintained aspect ratio, I should be able to use either
    //width or height to figure out scaling factor
    var scalingFactor = sketchRect.Width/buildingPathRect.Width;
    var scaleM = SKMatrix.MakeScale(scalingFactor, scalingFactor);
    //Next I need to handle translation so path is centered on canvas
    var secondTranslateM = SKMatrix.MakeTranslation(sketchRect.Left, sketchRect.Top);
    //Finally I need to handle transforming the path to rotate 180 degrees
    var rotationMatrix = SKMatrix.MakeRotationDegrees(180, sketchRect.MidX, sketchRect.MidY);
    //Now combine the translation, scaling, and rotation into a single matrix by matrix multiplication/concatentation
    var transformM = SKMatrix.MakeIdentity();
    SKMatrix.PostConcat(ref transformM, firstTranslateM);
    SKMatrix.PostConcat(ref transformM, scaleM);
    SKMatrix.PostConcat(ref transformM, secondTranslateM);
    SKMatrix.PostConcat(ref transformM, rotationMatrix);
    //Now apply the transform to the path
    foreach (var r in rooms)
    {
        r.Path.Transform(transformM);
    }
}

这是我想要的示例(忽略行号):

在此处输入图像描述

翻到:

在此处输入图像描述

任何帮助,将不胜感激。

4

1 回答 1

2

这种转换应该可以满足您的需求。术语将是水平翻转或反映水平。

    var Ma = new SKMatrix {Values = new float[] {-1, 0, 0, 1, 0, 0, 0, 0, 0}};
    pathToFlip.Transform(Ma);
于 2017-11-02T01:40:43.470 回答