W10 UWP - 将远程图像设置为桌面墙纸/锁屏
W10 UWP - Set remote image as desktop wallpaper / lockscreen
我正在尝试将远程图像设置为桌面墙纸/phone 我的 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
本地文件...
有人对解决问题有任何想法吗?
谢谢。
首先将您的远程图像保存到 ApplicationData.Current.LocalFolder
,然后使用 TrySetWallpaperImageAsync
/TrySetLockScreenImageAsync
并指向保存的图像而不是直接引用远程图像应该可行。
我正在尝试将远程图像设置为桌面墙纸/phone 我的 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
本地文件...
有人对解决问题有任何想法吗?
谢谢。
首先将您的远程图像保存到 ApplicationData.Current.LocalFolder
,然后使用 TrySetWallpaperImageAsync
/TrySetLockScreenImageAsync
并指向保存的图像而不是直接引用远程图像应该可行。