Search code examples
c#resizeuwptransforminkcanvas

How to change the size of InkCanvas Strokes in UWP?


I have an unsolved problem with my InkCanvas in my UWP App.

I saved my strokes in a SQLite Database from a InKCanvas with measurements a*b. Now I want to display this Strokes on another InkCanvas with different measurements than the InkCanvas with a*b (e.g. a/2 * b/2).

How can I change the size of my Strokes? I tried to use:

var allStrokes = myInkCanvas.InkPresenter.StrokeContainer.GetStrokes();
foreach(var item in allStrokes)
{
    item.PointTransform() = ...// I tried to transform my Strokey with a 3x2 Matrix
                               // But it didn't work. 
}

Maybe someone can help.


Solution

  • The transformation with matrix worked for me.

    I have used the Matrix3x2.CreateScale factory method as follows:

    var strokes = InkDisplay.InkPresenter.StrokeContainer.GetStrokes();
    foreach ( var stroke in strokes )
    {
        stroke.PointTransform = 
           Matrix3x2.CreateScale( 
              xScale,
              yScale 
           );
    }
    

    Note, that the xScale and yScale values represent relative scale, which means that when you go from ink canvas of size X*Y to ink canvas of size (X/2)*(Y*2), the values would be xScale = 0.5 and yScale = 2.

    You can see the sample I have created on my GitHub.