如何获取当前登录Windows的用户的图像帐户?

时间:2017-10-05 14:36:12

标签: c# wpf windows visual-studio c#-4.0

在网上搜索我发现这个代码UWP,以获取图像,但我无法在WPF中包含命名空间Windows.Storage。我试图包括所有可能的参考但不起作用。我会有一个解决方案WPF包含Windows.Storage(如果可能)或只是另一种方式来实现代码来获取图像

StorageFile image = UserInformation.GetAccountPicture(AccountPictureKind.SmallImage) as StorageFile;
        if (image != null)
        {
            rootPage.NotifyUser("SmallImage path = " + image.Path, NotifyType.StatusMessage);
        }
        else
        {
            rootPage.NotifyUser("Small Account Picture is not available", NotifyType.StatusMessage);
            mediaPlayer.Visibility = Visibility.Collapsed;
            smallImage.Visibility = Visibility.Collapsed;
            largeImage.Visibility = Visibility.Collapsed;

}

2 个答案:

答案 0 :(得分:2)

Windows.​System.​User​Profile命名空间用于UWP应用开发,不适用于WPF。

如果您将应用打包(转换)为UWP,则可以使用它:https://docs.microsoft.com/sv-se/windows/uwp/porting/desktop-to-uwp-supported-api#apis-supported-in-both-converted-apps-and-desktop-applications。请注意,Windows 10或更高版本不支持UserInformation类。相反,您应该使用User类。

在.NET应用程序中,您可以尝试在C:\Users\<user>\AppData\Roaming\Microsoft\Windows\Account Pictures文件夹中搜索最新修改的文​​件:

How to find the most recent file in a directory using .NET, and without looping?

答案 1 :(得分:0)

如果您查看this answer

,则基于here

只要您拥有当前登录的用户名,就应该可以访问它。对于Win OS 7至少就是这种情况,我不知道你正在使用哪种操作系统。

相关问题