Xamarin.forms SkiaSharp SVG图像未正确填充屏幕

Xamarin.forms SkiaSharp SVG图像未正确填充屏幕,xamarin.forms,skiasharp,Xamarin.forms,Skiasharp,我有一个SVG图像,我想用它填满整个屏幕。我的视图使用网格。以下是我的看法: <Grid> <Grid.RowDefinitions> <RowDefinition Height="60*" /> <RowDefinition Height="15*" /> <RowDefinition Height=&qu

我有一个SVG图像,我想用它填满整个屏幕。我的视图使用网格。以下是我的看法:

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="60*" />
            <RowDefinition Height="15*" />
            <RowDefinition Height="15*" />
            <RowDefinition Height="15*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="33*" />
            <ColumnDefinition Width="33*" />
            <ColumnDefinition Width="33*" />
        </Grid.ColumnDefinitions>

        <!--Damage view image-->
        <skia:SKCanvasView Grid.Row="0" 
                           Grid.Column="0" 
                           Grid.ColumnSpan="3" 
                           HorizontalOptions="FillAndExpand" 
                           VerticalOptions="FillAndExpand" 
                           EnableTouchEvents="True"
                           Touch="MarkDamage">
        </skia:SKCanvasView>
但是,这会使图像在侧面“溢出”。结果如下:


图像的右侧应该有一个小天线伸出,被切断。如何使图像正确匹配屏幕?

要根据边界画布/视图约束调整SVG图像的大小并使其居中,可以使用平移和缩放方法

// Get drawing surface bounds
var viewInfo = args.Info;
var drawBounds = viewInfo.Rect;

// Get bounding rectangle for SVG image
var boundingBox = svg.Picture.CullRect;

// Translate and scale drawing canvas to fit SVG image
canvas.Translate(drawBounds.MidX, drawBounds.MidY);
canvas.Scale(0.9f * 
    Math.Min(drawBounds.Width / boundingBox.Width, 
        drawBounds.Height / boundingBox.Height));
canvas.Translate(-boundingBox.MidX, -boundingBox.MidY);

// Now finally draw the SVG image
canvas.DrawPicture(svg.Picture);

// Optional -> Reset the matrix before performing more draw operations
canvas.ResetMatrix();

谢谢你,它在平板电脑和手机上都能正常工作。
// Get drawing surface bounds
var viewInfo = args.Info;
var drawBounds = viewInfo.Rect;

// Get bounding rectangle for SVG image
var boundingBox = svg.Picture.CullRect;

// Translate and scale drawing canvas to fit SVG image
canvas.Translate(drawBounds.MidX, drawBounds.MidY);
canvas.Scale(0.9f * 
    Math.Min(drawBounds.Width / boundingBox.Width, 
        drawBounds.Height / boundingBox.Height));
canvas.Translate(-boundingBox.MidX, -boundingBox.MidY);

// Now finally draw the SVG image
canvas.DrawPicture(svg.Picture);

// Optional -> Reset the matrix before performing more draw operations
canvas.ResetMatrix();