I'm trying to set a remote image as the desktop wallpaper / phone lockscreen in my W10 UWP app:
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
doesn't work as it is read-only, so I copy it to a new location (pictures library) to remove restrictions -> file2
.
Note: file3
works, so I'm not sure what's happening -- I assume TrySetWallpaperImageAsync/TrySetLockScreenImageAsync
only accepts msappx
local files...
Anyone have any ideas on work arounds?
Thanks.
To change the wallpaper in a domain user account, you must first have administrator privileges. Then, open the Control Panel and go to the "User Accounts" section. Select the "Change your desktop background" link. Choose the image you want to use as your wallpaper, and then click the "Save Changes" button.
Under Local Computer Policy, expand User Configuration, expand Administrative Templates, expand Desktop, and then click Active Desktop. Double-click Active Desktop Wallpaper. On the Setting tab, click Enabled, type the path to the desktop wallpaper that you want to use, and then click OK.
Save your remote image to ApplicationData.Current.LocalFolder
first, then use TrySetWallpaperImageAsync
/TrySetLockScreenImageAsync
and point to the saved image instead of directly referencing the remote image should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With