C# AspectFill无法处理xamarin中SkiaSharep中的已调整大小的图像,我该怎么办?

C# AspectFill无法处理xamarin中SkiaSharep中的已调整大小的图像,我该怎么办?,c#,image,xamarin,skiasharp,C#,Image,Xamarin,Skiasharp,我在模拟器上试过AspectFill,它可以工作,只有来自摄影机模拟器的图片,它们的分辨率很低,所以它们没有调整大小。但当我在手机上尝试这种方法时,我会发送一些代码和应用程序的屏幕截图,这些图片会通过SkiaSharp调整大小并保存为缩略图,但效果并不理想 调整大小代码: var bitmap = SKBitmap.Decode(Path); int h = bitmap.Height; int w = bitmap.Width; int ne

我在模拟器上试过AspectFill,它可以工作,只有来自摄影机模拟器的图片,它们的分辨率很低,所以它们没有调整大小。但当我在手机上尝试这种方法时,我会发送一些代码和应用程序的屏幕截图,这些图片会通过SkiaSharp调整大小并保存为缩略图,但效果并不理想

调整大小代码:

var bitmap = SKBitmap.Decode(Path);
        int h = bitmap.Height;
        int w = bitmap.Width;
        int newWidth = w;
        int newHeight = h;            
        
        if (h > 1080 || w > 1080)
        {
            int rectHeight = 1080;
            int rectWidth = 1080;

            //aspect ratio calculation   
            float W = w;
            float H = h;
            float aspect = W / H;                               

            //new dimensions by aspect ratio
            newWidth = (int)(rectWidth * aspect);
            newHeight = (int)(newWidth / aspect);                

            //if one of the two dimensions exceed the box dimensions
            if (newWidth > rectWidth || newHeight > rectHeight)
            {
                //depending on which of the two exceeds the box dimensions set it as the box dimension and calculate the other one based on the aspect ratio
                if (newWidth > newHeight)
                {
                    newWidth = rectWidth;
                    newHeight = (int)(newWidth / aspect);                        
                }
                else
                {
                    newHeight = rectHeight;
                    newWidth = (int)(newHeight * aspect);                        
                }
            }                              
        }
                
            
        var resizedImage = bitmap.Resize(new SKImageInfo(newWidth, newHeight), SKBitmapResizeMethod.Lanczos3);
        var image = resizedImage.Encode(SKEncodedImageFormat.Jpeg, 80);
        var path = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);            
        var filepath = System.IO.Path.Combine(path, fileName);
        string finalPath = filepath;
        using (var stream = File.OpenWrite(filepath))            
            image.SaveTo(stream);            
        return finalPath;
集合视图:

<DataTemplate>
                    <StackLayout Margin="0">
                        <Frame Padding="0" BackgroundColor="{AppThemeBinding Light='#00d2ff', Dark='#121212'}" Margin="0, 70, 0, 0" CornerRadius="30">
                            <StackLayout Padding="20">
                                <Label Text="{Binding Airline}" TextColor ="White" FontAttributes="Bold" FontSize="35" FontFamily="Lato" Margin="0" HorizontalOptions="Center" HorizontalTextAlignment="Center"/>
                                <Grid HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">
                                    <Image Source="{Binding ThumbnailUrl}" Aspect="AspectFill"/>
                                </Grid>
                                <Label Text="{Binding Plane, StringFormat='Plane: {0}'}" FontFamily="Lato" TextColor ="White" FontSize="15"/>
                                <Label Text="{Binding Airline, StringFormat='Airline: {0}'}" FontFamily="Lato" TextColor ="White" FontSize="15"/>
                                <Label Text="{Binding Livery, StringFormat='Livery: {0}'}" FontFamily="Lato" TextColor ="White" FontSize="15"/>
                                <Label Text="{Binding Registration, StringFormat='Reg: {0}'}" FontFamily="Lato" TextColor ="White" FontSize="15"/>
                                <Label Text="{Binding Airport, StringFormat='Airport: {0}'}" FontFamily="Lato" TextColor ="White" FontSize="15"/>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <StackLayout Grid.Column="0">
                                        <Label Text="{Binding Date, StringFormat='Date: {0}'}" FontFamily="Lato" TextColor ="White" FontSize="15"/>
                                        <Label Text="{Binding Comment, StringFormat='Comment: {0}'}" FontFamily="Lato" TextColor ="White" FontSize="15"/>
                                    </StackLayout>
                                    <AbsoluteLayout Grid.Column="1">
                                        <Button Text="Delete" TextColor="White" CornerRadius="30" FontAttributes="Bold" FontSize="14" FontFamily="Lato" BackgroundColor="#00aeef" x:Name="deleteButton" Clicked="deleteButton_Clicked" AbsoluteLayout.LayoutBounds="0.8, 0.5, 100, 50" AbsoluteLayout.LayoutFlags="PositionProportional"/>
                                    </AbsoluteLayout>
                                </Grid>
                            </StackLayout>
                        </Frame>
                    </StackLayout>
                </DataTemplate>

我已经用FFImageLoading完成了:

<Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                                    <ff:CachedImage Source="{Binding ThumbnailUrl}"
                                                    HorizontalOptions="FillAndExpand"
                                                    VerticalOptions="FillAndExpand"
                                                    
                                                    Aspect="AspectFill"
                                                    DownsampleToViewSize="True"/>
                                </Grid>


在您更新后的XAML中,您没有在任何地方使用AspectFill,但仍然不起作用