private void DoTransition(FileInfo newWallpaper, FileInfo currentWp) { if (currentWp.Exists) { FileInfo resultWp = new FileInfo(Path.Combine(Path.GetTempPath(), "transform.bmp")); currentWp = currentWp.CopyTo(Path.Combine(Path.GetTempPath(), "original.bmp"), true); currentWp.Refresh(); float alphaIncrement = 1.0f / _TransitionSlices; int timeIncrement = Convert.ToInt32(_TransitionTime / _TransitionSlices); for (float i = .0f; i <= 1f; i += alphaIncrement) { if (!_Running) { break; } MatrixBlend(currentWp.FullName, newWallpaper.FullName, resultWp.FullName, i); resultWp.Refresh(); Win32Wallpaper.Set(resultWp, _WallpaperStyle); resultWp.Delete(); resultWp.Refresh(); Thread.Sleep(timeIncrement); } resultWp = newWallpaper.CopyTo(Path.Combine(Path.GetTempPath(), "wallpaper.bmp"), true); resultWp.Refresh(); Win32Wallpaper.Set(resultWp, _WallpaperStyle); resultWp.Refresh(); } //if (newWp.Exists) // Wallpaper.Set(newWp, Wallpaper.Style.Centered); }
private void ChangeWallpaper() { LoadConfig(); DateTime now = DateTime.Now; TimeSpan n = now - new DateTime(now.Year, now.Month, now.Day); TimeSpan timeSlot = TimeSpan.MinValue; foreach (TimeSpan key in _TimeSlots.Keys) { if (key <= n) { timeSlot = key; } else { break; } } if (timeSlot == TimeSpan.MinValue) { return; } if (_LastTimeSlot != timeSlot) { _LastTimeSlot = timeSlot; FileInfo newWp = new FileInfo(_TimeSlots[timeSlot]); FileInfo currentWp = new FileInfo(Path.Combine(Path.GetTempPath(), "wallpaper.bmp")); /*if (!newWp.Exists) * return;*/ if (currentWp.Exists) { DoTransition(newWp, currentWp); } else { Win32Wallpaper.Set(newWp, _WallpaperStyle); } } }