///<inheritdoc/> public async Task <bool> TrySetWallpaperImageAsync(string imageFilePath) { if (String.IsNullOrEmpty(imageFilePath)) { throw new ArgumentNullException(nameof(imageFilePath)); } bool success = false; //remove old wallpapers await FileService.CleanUpFolderAsync(ApplicationData.Current.LocalFolder, FileTypeFilter, 0); if (UserProfilePersonalizationSettings.IsSupported()) { StorageFile wallpaper; if (!imageFilePath.Contains(ApplicationData.Current.LocalFolder.Path)) { StorageFile originalStorageFile = await StorageFile.GetFileFromPathAsync(imageFilePath); wallpaper = await ApplicationData.Current.LocalFolder.CreateFileAsync( new FileInfo(imageFilePath).Name, CreationCollisionOption.GenerateUniqueName); await originalStorageFile.CopyAndReplaceAsync(wallpaper); } else { wallpaper = await StorageFile.GetFileFromPathAsync(imageFilePath); } UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; success = await profileSettings.TrySetWallpaperImageAsync(wallpaper); } return(success); }
/// <summary> /// Returns the current contents of the cache folder /// </summary> /// <returns></returns> private async Task <bool> SetBackgroundImage(UpdateTypes type, StorageFile file) { bool wasSuccess = false; if (type == UpdateTypes.Band) { wasSuccess = await m_baconMan.BackgroundMan.BandMan.UpdateBandWallpaper(file); // The band can fail quite a lot, if so don't count this as a fail. wasSuccess = true; } // Make sure we can do it else if (UserProfilePersonalizationSettings.IsSupported()) { // Try to set the image UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; if (type == UpdateTypes.LockScreen) { wasSuccess = await profileSettings.TrySetLockScreenImageAsync(file); } else { wasSuccess = await profileSettings.TrySetWallpaperImageAsync(file); } } return(wasSuccess); }
public Picture(string fileName, DateTime dateCreated, string filePath) { FileName = fileName; DateCreated = dateCreated; FilePath = filePath; ImageSource = new BitmapImage(); this.SetAsBackgroundCommand = new RelayCommand(async() => { if (UserProfilePersonalizationSettings.IsSupported()) { var file = await SaveImage("backgroundimage.jpg"); UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; Debug.Write(await profileSettings.TrySetWallpaperImageAsync(file)); } }); this.SetAsLockscreenCommand = new RelayCommand(async() => { if (UserProfilePersonalizationSettings.IsSupported()) { var file = await SaveImage("lockscreenimage.jpg"); UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; Debug.Write(await profileSettings.TrySetLockScreenImageAsync(file)); } }); }
private async void btnSetWallpaper_Click(object sender, RoutedEventArgs e) { if (UserProfilePersonalizationSettings.IsSupported()) { UserProfilePersonalizationSettings settings = UserProfilePersonalizationSettings.Current; StorageFile cacheFile = await CacheManager.GetCachedFileAsync(parameter.FileName); StorageFile file = await cacheFile.CopyAsync(ApplicationData.Current.LocalFolder, "WallpaperImage", NameCollisionOption.ReplaceExisting); if (!await settings.TrySetWallpaperImageAsync(file)) { var messageDialog = new MessageDialog("更换壁纸失败"); await messageDialog.ShowAsync(); } else { await ShowTip("已更换壁纸"); } } else { var messageDialog = new MessageDialog("您的设备不支持更换壁纸"); await messageDialog.ShowAsync(); } }
public async void SetAsDesktopBackgroundItem_Click(object sender, RoutedEventArgs e) { var item = (CurrentInstance.ContentPage as BaseLayout).SelectedItem; StorageFile file = await StorageFile.GetFileFromPathAsync(item.FilePath); UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; await profileSettings.TrySetWallpaperImageAsync(file); }
private async void SetWallpaperAsync() { var file = await GetOrCreateAppDataImageFileAsync("Wallpaper.png"); var success = await _personalizationSettings.TrySetWallpaperImageAsync(file); await ShowResultDialogAsync(success); }
//public StorageFile Storagefile { get => sf; set=>sf = value; } private async void StartBackground_Click(object sender, RoutedEventArgs e) { sf = await sfd.CreateFileAsync(imgid + ".jpg", CreationCollisionOption.ReplaceExisting); await ImgTransfromAsync(); //sf = await StorageFile.GetFileFromPathAsync(imgLocalpath); UserProfilePersonalizationSettings startsetting = UserProfilePersonalizationSettings.Current; bool b = await startsetting.TrySetWallpaperImageAsync(sf); }
public async Task <bool> setWallpaper(StorageFile imageFile) { bool success = false; if (UserProfilePersonalizationSettings.IsSupported()) { UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; success = await profileSettings.TrySetWallpaperImageAsync(imageFile); } return(success); }
private async Task <bool> SetWallpaper(StorageFile wallpaperImage) { bool successful = false; if (UserProfilePersonalizationSettings.IsSupported()) { UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; successful = await profileSettings.TrySetWallpaperImageAsync(wallpaperImage); } return(successful); }
private static async Task SetDesktopBackgroundAsync(StorageFile file) { if (UserProfilePersonalizationSettings.IsSupported()) { StorageFile localFile = await file.CopyAsync(ApplicationData.Current.LocalFolder, file.Name, NameCollisionOption.ReplaceExisting); UserProfilePersonalizationSettings settings = UserProfilePersonalizationSettings.Current; await settings.TrySetWallpaperImageAsync(localFile); } }
// Change wallpaper // Pass in a relative path to a file inside the assets folder async Task <bool> SetWallpaperAsync(string assetsFileName) { if (UserProfilePersonalizationSettings.IsSupported()) { var uri = new Uri("ms-appx:///Assets/" + assetsFileName); StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri); UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; return(await profileSettings.TrySetWallpaperImageAsync(file)); } return(false); }
public async void SetWallappaer(string url) { StorageFile file = await HomeController.DownloadImagefromServer(url, "wall"); bool success = false; if (UserProfilePersonalizationSettings.IsSupported()) { UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; success = await profileSettings.TrySetWallpaperImageAsync(file); } }
public static async Task <bool> ChangeWallPaper(StorageFile imageFile) { if (UserProfilePersonalizationSettings.IsSupported()) { UserProfilePersonalizationSettings settings = UserProfilePersonalizationSettings.Current; return(await settings.TrySetWallpaperImageAsync(imageFile)); } else { return(false); } }
private async Task <bool> SetWallpaperAsyncInternal(string localAppDataFileName) { bool success = false; if (UserProfilePersonalizationSettings.IsSupported()) { var file = await ApplicationData.Current.LocalFolder.GetFileAsync(localAppDataFileName); UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; success = await profileSettings.TrySetWallpaperImageAsync(file); } return(success); }
/// <summary> /// 改变桌面壁纸。 /// </summary> /// <param name="localAppDataFileName"></param> /// <returns>是否操作成功。</returns> public async Task <bool> SetWallpaperAsync(string localAppDataFileName) { bool success = false; if (UserProfilePersonalizationSettings.IsSupported()) { var uri = new Uri("ms-appdata:///local/" + localAppDataFileName); StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri); UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; success = await profileSettings.TrySetWallpaperImageAsync(file); } return(success); }
private IAsyncOperation <bool> SetWallpaperAsync(StorageFile wallpaperImage) { bool successful = false; return(Task.Run <bool>(async() => { if (UserProfilePersonalizationSettings.IsSupported()) { UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; successful = await profileSettings.TrySetWallpaperImageAsync(wallpaperImage); } return successful; }).AsAsyncOperation()); }
//设置壁纸 //复制壁纸到localFolder public async void writeasset桌面(StorageFile file) { //StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/桌面.jpg")); StorageFile tmp = await file.CopyAsync(ApplicationData.Current.LocalFolder, "桌面.jpg", NameCollisionOption.ReplaceExisting); bool success = false; //检查是否支持 if (UserProfilePersonalizationSettings.IsSupported()) { UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; success = await profileSettings.TrySetWallpaperImageAsync(tmp); } }
async Task <bool> SetWallpaperAsync(string iFile) { bool success = false; if (UserProfilePersonalizationSettings.IsSupported()) { var uri = new Uri(this.BaseUri, "C:\\Users\\Deepak\\Pictures\\" + iFile); StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri); UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; success = await profileSettings.TrySetWallpaperImageAsync(file); } return(success); }
private async Task ChangeBackground() { if (UserProfilePersonalizationSettings.IsSupported()) { Uri urichangewallpaper; if (newItem == null) { urichangewallpaper = new Uri(itemaaa.cover_photo.urls.full); } else { urichangewallpaper = new Uri(newItem.urls.full); } using (Windows.Web.Http.HttpClient client = new Windows.Web.Http.HttpClient()) { try { Windows.Web.Http.HttpResponseMessage response = await client.GetAsync(urichangewallpaper); if (response != null && response.StatusCode == Windows.Web.Http.HttpStatusCode.Ok) { string filename = "background.jpg"; var imageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); using (IRandomAccessStream stream = await imageFile.OpenAsync(FileAccessMode.ReadWrite)) { await response.Content.WriteToStreamAsync(stream); } StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(filename); UserProfilePersonalizationSettings settings = UserProfilePersonalizationSettings.Current; if (!await settings.TrySetWallpaperImageAsync(file)) { System.Diagnostics.Debug.WriteLine("Failed"); } else { System.Diagnostics.Debug.WriteLine("Success"); } } } catch { } } } }
public async void SetAsDesktopBackgroundItem_Click(object sender, RoutedEventArgs e) { // Get the path of the selected file StorageFile sourceFile = await StorageFile.GetFileFromPathAsync(CurrentInstance.ContentPage.SelectedItem.ItemPath); // Get the app's local folder to use as the destination folder. StorageFolder localFolder = ApplicationData.Current.LocalFolder; // Copy the file to the destination folder. // Replace the existing file if the file already exists. StorageFile file = await sourceFile.CopyAsync(localFolder, "Background.png", NameCollisionOption.ReplaceExisting); // Set the desktop background UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; await profileSettings.TrySetWallpaperImageAsync(file); }
public async Task UpdateImage(CancellationTokenSource _source) { var saveFile = await GetLiveEarthPictureForWallPaper(_source); if (saveFile == null) { return; } if (UserProfilePersonalizationSettings.IsSupported()) { UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; var success = await profileSettings.TrySetWallpaperImageAsync(saveFile); //download_status.Text = success ? "success" : "failed"; } }
/// <summary> /// Returns the current contents of the cache folder /// </summary> /// <returns></returns> private async Task <bool> SetBackgroundImage(UpdateTypes type, StorageFile file) { bool wasSuccess = false; // Try to set the image UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; if (type == UpdateTypes.LockScreen) { wasSuccess = await profileSettings.TrySetLockScreenImageAsync(file); } else { wasSuccess = await profileSettings.TrySetWallpaperImageAsync(file); } return(wasSuccess); }
private async Task LockScreenBackground() { if (UserProfilePersonalizationSettings.IsSupported()) { string filename = "background.jpg"; StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(filename); UserProfilePersonalizationSettings settings = UserProfilePersonalizationSettings.Current; if (!await settings.TrySetWallpaperImageAsync(file)) { System.Diagnostics.Debug.WriteLine("Failed"); } else { System.Diagnostics.Debug.WriteLine("Success"); } } }
private async void btnAplicar_Click(object sender, RoutedEventArgs e) { ContentDialog setWallpaperDialog = new ContentDialog { Title = "Aplicar wallpaper como fondo de pantalla?", Content = $"Desea aplicar la imagen {imagenSeleccionada.Nombre} como fondo de pantalla?", CloseButtonText = "Cancelar", PrimaryButtonText = "Aplicar" }; ContentDialogResult result = await setWallpaperDialog.ShowAsync(); if (result == ContentDialogResult.Primary) { UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; await profileSettings.TrySetWallpaperImageAsync(files[imagenSeleccionada.Posicion]); } }
/// <summary> /// Returns the current contents of the cache folder /// </summary> /// <returns></returns> private async Task <bool> SetBackgroundImage(bool isLockScreen, StorageFile file) { bool wasSuccess = false; // Make sure we can do it if (UserProfilePersonalizationSettings.IsSupported()) { // Try to set the image UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; if (isLockScreen) { wasSuccess = await profileSettings.TrySetLockScreenImageAsync(file); } else { wasSuccess = await profileSettings.TrySetWallpaperImageAsync(file); } } return(wasSuccess); }
public static async Task ApplyImagetoWallpaperAsync(StorageFile file) { ApplicationDataContainer settings = ApplicationData.Current.LocalSettings; if ((string)settings.Values["UseWeatherForDesktop"] == "true") { if (UserProfilePersonalizationSettings.IsSupported()) { UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; await profileSettings.TrySetWallpaperImageAsync(file); } } if ((string)settings.Values["UseWeatherForLockscreen"] == "true") { if (UserProfilePersonalizationSettings.IsSupported()) { UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; await profileSettings.TrySetLockScreenImageAsync(file); } } }
private async void SetWallpaper() { if (UserProfilePersonalizationSettings.IsSupported()) { progressImage2.IsActive = true; textBlockWallpaper.Visibility = Visibility.Visible; textBlockWallpaper.Text = "Descargando wallpaper"; btnAplicar.IsEnabled = false; bool descarga = await DownloadImage(nasa.hdurl, $"{nasa.title}.jpg"); if (descarga) { textBlockWallpaper.Text = "Aplicando wallpaper"; UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; bool res = await profileSettings.TrySetWallpaperImageAsync(fileFondo); if (res) { progressImage2.IsActive = false; textBlockWallpaper.Visibility = Visibility.Collapsed; btnAplicar.IsEnabled = true; } else { progressImage2.IsActive = false; textBlockWallpaper.Text = "Error al establecer wallpaper"; btnAplicar.IsEnabled = true; } } else { progressImage2.IsActive = false; textBlockWallpaper.Text = "Error en la descarga"; btnAplicar.IsEnabled = true; } } }
public static async Task <bool> setWallpaper(string filename) { StorageFolder fold = Windows.Storage.ApplicationData.Current.LocalFolder; var file = await fold.GetFileAsync(filename); UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; //bool success = await profileSettings.TrySetLockScreenImageAsync(file); bool success = await profileSettings.TrySetWallpaperImageAsync(file); var timer = new Windows.UI.Xaml.DispatcherTimer { Interval = TimeSpan.FromSeconds(0.5) }; timer.Tick += (sender, args) => { MainPage.initTitlebar(); timer.Stop(); }; timer.Start(); return(success); }
public static async void SetAsBackground(WallpaperType type, string filePath, IShellPage associatedInstance) { if (UserProfilePersonalizationSettings.IsSupported()) { // Get the path of the selected file BaseStorageFile sourceFile = await StorageHelpers.ToStorageItem <BaseStorageFile>(filePath, associatedInstance); if (sourceFile == null) { return; } // Get the app's local folder to use as the destination folder. BaseStorageFolder localFolder = ApplicationData.Current.LocalFolder; // the file to the destination folder. // Generate unique name if the file already exists. // If the file you are trying to set as the wallpaper has the same name as the current wallpaper, // the system will ignore the request and no-op the operation BaseStorageFile file = await FilesystemTasks.Wrap(() => sourceFile.CopyAsync(localFolder, sourceFile.Name, NameCollisionOption.GenerateUniqueName).AsTask()); if (file == null) { return; } UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; if (type == WallpaperType.Desktop) { // Set the desktop background await profileSettings.TrySetWallpaperImageAsync(await file.ToStorageFileAsync()); } else if (type == WallpaperType.LockScreen) { // Set the lockscreen background await profileSettings.TrySetLockScreenImageAsync(await file.ToStorageFileAsync()); } } }
public async Task <bool> SetAsAsync(string Uri = null, StorageFile image = null, SetAs setAs = SetAs.Wallpaper) { bool success = false; StorageFile file; if (UserProfilePersonalizationSettings.IsSupported()) { try { file = image ?? await StorageFile.GetFileFromPathAsync(Uri) ?? throw new ArgumentNullException(nameof(image)); } catch (Exception) { throw; } var wallpaperPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "Wallpaper"); if (!Directory.Exists(wallpaperPath)) { Directory.CreateDirectory(wallpaperPath); } IStorageFolder wallpaperFolder = await StorageFolder.GetFolderFromPathAsync(wallpaperPath); var copiedFile = await file.CopyAsync(wallpaperFolder, file.Name, NameCollisionOption.ReplaceExisting); UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current; if (setAs == SetAs.Wallpaper) { success = await profileSettings.TrySetWallpaperImageAsync(copiedFile); } else { success = await profileSettings.TrySetLockScreenImageAsync(copiedFile); } } return(success); }