W10 UWP -设置远程图像为桌面壁纸/锁屏

本文关键字:图像 桌面壁纸 锁屏 UWP 设置 程图像 W10 | 更新日期: 2023-09-27 18:06:45

我试图在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本地文件…

谁有什么关于工作的想法?

谢谢。

W10 UWP -设置远程图像为桌面壁纸/锁屏

首先将远程图像保存到ApplicationData.Current.LocalFolder,然后使用TrySetWallpaperImageAsync/TrySetLockScreenImageAsync并指向保存的图像,而不是直接引用远程图像。