2017-10-05 124 views
0

在網上搜索我發現這個代碼UWP,得到的圖像,但我不能在WPF中包含命名空間Windows.Storage。我試圖包含所有可能的引用,但不起作用。我想有一個解決方案WPF包括Windows.Storage(如果可能),或者乾脆另一種方式來實現代碼來獲得圖像如何獲取當前登錄Windows的用戶的圖像帳戶?

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; 

}

+0

此代碼片段似乎適用於UWP。 – mm8

+0

我認爲他們可能存儲在'C:\ Users \ \ AppData \ Roaming \ Microsoft \ Windows \ AccountPictures' – itsme86

+0

@ itsme86謝謝,但在文件夾中我可以找到用於帳戶的所有照片。我應該得到目前使用的照片。 –

回答

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?

+0

獲得圖像非常感謝。我認爲最簡單的解決方案是在文件夾中找到最新的修改文件 –

0

基於this answer如果你看一看here

只要你擁有當前登錄的用戶名,您應該可以訪問它。至少在Win OS 7中,我不知道你正在使用哪個操作系統。

相關問題