protected void ChangeImage()
 {
     if (_imageFiles == null)
     {
         _imageFiles     = GetImagesFromDirectory();
         _imageFilesPath = _imageFiles.GetEnumerator();
     }
     if (_imageFilesPath.MoveNext())
     {
         FireImageAvailable();
         _timer.Restart();
     }
     else
     {
         // Reached the end of the images. Loop to beginning?
         if (Setting.LoopSlideshow)
         {
             _imageFilesPath.Reset();
             if (_imageFilesPath.MoveNext())
             {
                 FireImageAvailable();
                 _timer.Restart();
             }
             else
             {
                 _timer.Stop();
             }
         }
         else
         {
             _timer.Stop();
         }
     }
 }
 protected override void OnSettingChanged(object sender, EventArgs e)
 {
     if ((sender as Setting)?.ImageBackgroundType != ImageBackgroundType.SingleEach)
     {
         return;
     }
     _imageFiles     = GetImagesFromDirectory();
     _imageFilesPath = _imageFiles.GetEnumerator();
     NextImage();
 }
        public override BitmapSource GetBitmap()
        {
            if (_imageFiles == null)
            {
                _imageFiles     = GetImagesFromDirectory();
                _imageFilesPath = _imageFiles.GetEnumerator();
                _imageFilesPath.MoveNext();
                _timer.Restart();
            }
            var current = _imageFilesPath?.Current;

            if (string.IsNullOrEmpty(current))
            {
                return(null);
            }

            var bitmap   = new BitmapImage();
            var fileInfo = new FileInfo(current);

            if (fileInfo.Exists)
            {
                bitmap.BeginInit();
                bitmap.CacheOption   = BitmapCacheOption.OnLoad;
                bitmap.CreateOptions = BitmapCreateOptions.None;
                bitmap.UriSource     = new Uri(current, UriKind.RelativeOrAbsolute);
                bitmap.EndInit();
                bitmap.Freeze();
            }
            else
            {
                OnSettingChanged(null, null);
                return(GetBitmap());
            }


            BitmapSource ret_bitmap = bitmap;

            if (Setting.ImageStretch == ImageStretch.None)
            {
                bitmap = Utils.EnsureMaxWidthHeight(bitmap, Setting.MaxWidth, Setting.MaxHeight);
                if (bitmap.Width != bitmap.PixelWidth || bitmap.Height != bitmap.PixelHeight)
                {
                    ret_bitmap = Utils.ConvertToDpi96(bitmap);
                }
            }

            if (Setting.SoftEdgeX > 0 || Setting.SoftEdgeY > 0)
            {
                ret_bitmap = Utils.SoftenEdges(ret_bitmap, Setting.SoftEdgeX, Setting.SoftEdgeY);
            }

            return(ret_bitmap);
        }
 public void NextImage()
 {
     if (_imageFiles == null)
     {
         _imageFiles     = GetImagesFromDirectory();
         _imageFilesPath = _imageFiles.GetEnumerator();
     }
     if (!_imageFilesPath.MoveNext())
     {
         if (Setting.LoopSlideshow)
         {
             _imageFilesPath.Reset();
             _imageFilesPath.MoveNext();
         }
     }
 }
        protected override void OnSettingChanged(object sender, EventArgs e)
        {
            if (_timer != null)
            {
                _timer.Stop();
                _timer.Elapsed -= OnTimerElapsed;
                _timer.Dispose();
            }
            _timer          = new PausableTimer(Setting.UpdateImageInterval.TotalMilliseconds);
            _timer.Elapsed += OnTimerElapsed;

            if ((sender as Setting)?.ImageBackgroundType != ImageBackgroundType.Slideshow)
            {
                _timer.Stop();
            }
            else
            {
                _imageFiles     = GetImagesFromDirectory();
                _imageFilesPath = _imageFiles.GetEnumerator();
                ChangeImage();
                _timer.Restart();
            }
        }