DeviceInformation.GetGlyphThumbnailAsync总是得到黑暗的主题缩略图

时间:2017-03-13 14:02:20

标签: xaml uwp

我是UWP的新手,尝试访问缩略图,我正在变暗主题图像。 App.xaml请求的主题是轻量级

.cs
     DeviceThumbnail deviceThumbnail = await DeviceInformation.GetGlyphThumbnailAsync();
                var glyphBitmapImage = new BitmapImage();
.xaml
     <Image Source="{x:Bind GlyphBitmapImage, Mode=OneWay}" Stretch="UniformToFill" RequestedTheme="Light" Grid.Column="0" Height="40" Width="40" Margin="5" VerticalAlignment="Top"/>

请帮我解决。

如果windows 10灯光主题我可以看到设置图像为 enter image description here

1 个答案:

答案 0 :(得分:0)

大多数系统图像仅在透明背景上以纯白图像的形式存在。这是您在致电GetGlyphThubnailAsync()时看到的内容。

因为这些图像只包含单一颜色和Alpha通道,所以如果您需要不同的版本(例如颜色不同),它们很容易操作。

将返回的缩略图更改为白底黑字的最简单方法是使用WriteableBitmapEx中的Invert()方法。
假设这个XAML:

<Image x:Name="GlyphImage" />
<Image x:Name="InvertedGlyphImage" />

他们可以像这样填充:

var thumbnail = await deviceInfo.GetGlyphThumbnailAsync();

var regular = new BitmapImage();
regular.SetSource(thumbnail);

GlyphImage.Source = regular;

var wb = new WriteableBitmap(regular.PixelWidth, regular.PixelHeight);
var newWb = await wb.FromStream(thumbnail);

InvertedGlyphImage.Source = newWb.Invert();

并将产生如下输出:

enter image description here

我还注意到您在用于显示的图像上设置了RequestedTheme属性。请注意,此属性告诉FrameworkElement在呈现其UI时使用哪种系统样式。这不会对您显示的位图产生任何影响。