我正在尝试在我的W10 UWP应用程序中将远程图像设置为桌面壁纸/手机锁屏:
string name = "test_image.jpg";
Uri uri = new Uri("http://www.ucl.ac.uk/news/news-articles/1213/muscle-fibres-heart.jpg");
// download image from uri into temp storagefile
var file = await StorageFile.CreateStreamedFileFromUriAsync(name, uri, RandomAccessStreamReference.CreateFromUri(uri));
// file is readonly, copy to a new location to remove restrictions
var file2 = await file.CopyAsync(KnownFolders.PicturesLibrary);
// test -- WORKS!
//var file3 = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Design/1.jpg"));
// try set lockscreen/wallpaper
if (ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")) // Phone
success = await UserProfilePersonalizationSettings.Current.TrySetLockScreenImageAsync(file2);
else // PC
success = await UserProfilePersonalizationSettings.Current.TrySetWallpaperImageAsync(file2);
file1
由于只读权限无法使用,所以我将其复制到新位置(图片库)以消除限制,生成file2
。
注意:file3
可以正常工作,所以我不确定发生了什么情况——我猜测TrySetWallpaperImageAsync/TrySetLockScreenImageAsync
只接受本地的msappx
文件...有没有任何解决方法?
谢谢。