Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# StorageItemThumbnail中的位图在GridView中显示错误的尺寸_C#_Image_Gridview_Uwp - Fatal编程技术网

C# StorageItemThumbnail中的位图在GridView中显示错误的尺寸

C# StorageItemThumbnail中的位图在GridView中显示错误的尺寸,c#,image,gridview,uwp,C#,Image,Gridview,Uwp,我目前正在开发一个应用程序,一个我似乎无法理解的错误是: 这些图像是PDF页面快照,实际上是纵向格式的。不知何故,它无法正确显示。我可以看到错误的尺寸和它应该显示的尺寸 有人知道为什么会这样吗 转换器代码: public object Convert(object value, Type targetType, object parameter, string language) { BitmapImage image = null; if (value != null)

我目前正在开发一个应用程序,一个我似乎无法理解的错误是:

这些图像是PDF页面快照,实际上是纵向格式的。不知何故,它无法正确显示。我可以看到错误的尺寸和它应该显示的尺寸

有人知道为什么会这样吗

转换器代码:

public object Convert(object value, Type targetType, object parameter, string language)
{
    BitmapImage image = null;

    if (value != null)
    {
        if (value.GetType() != typeof(StorageItemThumbnail))
        {
            throw new ArgumentException("Expected a StorageItemThumbnail as binding input.");
        }

        if (targetType != typeof(ImageSource))
        {
            throw new ArgumentException("Expected ImageSource as binding output.");
        }

        if ((StorageItemThumbnail)value == null)
        {
            System.Diagnostics.Debug.WriteLine("Thumbnail is null.");
            return image;
        }

        image = new BitmapImage();
        using (var thumbNailClonedStream = ((StorageItemThumbnail)value).CloneStream())
        {
            image.DecodePixelType = DecodePixelType.Logical;

            _ = image.SetSourceAsync(thumbNailClonedStream);
        }
    }

    return image;
}
缩略图检索(destinationFile=StorageFile):

GridView XAML:

<GridView Name="pagesViewer" ItemsSource="{x:Bind CurrentPages, Mode=OneWay}" Margin="0,0,0,40" Grid.Row="1" CanDrag="True" CanDragItems="True" CanReorderItems="True" Background="White" AllowDrop="True" Drop="pagesViewer_Drop" DragOver="pagesViewer_DragOver">
    <GridView.ItemTemplate>
        <DataTemplate x:DataType="local:AppPage">
            <StackPanel Height="280" Width="200" Margin="12" AutomationProperties.Name="{x:Bind PageNumber}" ToolTipService.ToolTip="{x:Bind OriginalFile.Name}" Background="WhiteSmoke" IsRightTapEnabled="True">
                <StackPanel.ContextFlyout>
                    <MenuFlyout>
                        <MenuFlyout.Items>
                            <MenuFlyoutItem x:Name="DeletePage" Text="Remove Page" />
                            <MenuFlyoutItem x:Name="AddBlankBefore" Text="Add Blank Before" />
                            <MenuFlyoutItem x:Name="AddBlankAfter" Text="Add Blank After" />
                        </MenuFlyout.Items>
                    </MenuFlyout>
                </StackPanel.ContextFlyout>
                <Image Source="{x:Bind Thumbnail, Converter={StaticResource ResourceKey=ThumbnailConverter}}" Height="240" Width="200" Stretch="Uniform" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
                <StackPanel Margin="0,12">
                    <TextBlock Text="{x:Bind PageNumber, Mode=OneWay}" Foreground="Black" FontWeight="Light" FontSize="15" TextAlignment="Center" />
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </GridView.ItemTemplate>
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <ItemsWrapGrid MaximumRowsOrColumns="10" Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
</GridView>

StorageItemThumbnail中的位图在GridView中显示错误的尺寸

请参阅文档,缩略图最长边的要求大小(以像素为单位)。Windows使用
requestedSize
作为指导,尝试缩放缩略图图像,而不降低图像的质量。当您将
ThumbnailMode
as设置为并调用GetThumbnailAsync方法时,如下所示

await destinationFile.GetThumbnailAsync(ThumbnailMode.PicturesView, 500, ThumbnailOptions.UseCurrentScale);
它将以19/13剪切图像,然后宽度限制为500,高度限制为342

对于您的场景,我们建议您使用
ThumbnailMode.SingleItem
替换上述内容,并将图像拉伸属性设置为
Fill

StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 500, ThumbnailOptions.ResizeThumbnail);

这确实奏效了!
StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 500, ThumbnailOptions.ResizeThumbnail);