加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – W10 UWP – 将远程图像设置为桌面墙纸/锁屏

发布时间:2020-12-15 08:04:37 所属栏目:百科 来源:网络整理
导读:我正在尝试在我的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 storagefilev
我正在尝试在我的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无法正常工作,因此我将其复制到新位置(图片库)以删除限制 – >文件2.

注意:file3有效,所以我不确定发生了什么 – 我假设TrySetWallpaperImageAsync / TrySetLockScreenImageAsync只接受msappx本地文件…

任何人都有关于工作的想法?

谢谢.

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读