2017-10-21 1 views
1

나는 발견 한 예제에 따라 약간 수정 된 크기 조정 코드를 사용하고 있습니다. 그러나 크기를 변경하면 모든 내용이 뒤집 힙니다. 다시 뒤집거나 처음부터 뒤집지 않도록하고 싶습니다.SkiaSharp를 사용하여 SKPath를 뒤집기

enter image description here

가 뒤집혀 :

다음
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); 
    } 
} 

내가 원하는 내용의 예 (줄 번호를 무시)입니다 : 여기

내 크기 조정 코드

enter image description here

어떤 도움을 주시면 감사하겠습니다.

+0

두 번째 링크가 작동하지 않습니다. –

+0

수정 됨. 일부 서식을 정리해 주셔서 감사합니다. – jdm

답변

1

이 변환은 찾고자하는 것을 수행해야합니다. 용어는 수평으로 뒤집거나 수평을 반영합니다.

var Ma = new SKMatrix {Values = new float[] {-1, 0, 0, 1, 0, 0, 0, 0, 0}}; 
    pathToFlip.Transform(Ma); 
관련 문제