public void ResourceTest()
        {
            var image = ImageSourceManager.GetImage("resources:/Resources/Images/icon_dark.png", false);

            Assert.IsNotNull(image);
            Assert.AreNotEqual(DependencyProperty.UnsetValue, image);
        }
        public void LocalFileTest()
        {
            var image  = Path.Combine(PlaynitePaths.ProgramPath, "Resources", "Images", "applogo.png");
            var result = ImageSourceManager.GetImage(image, false);

            Assert.AreEqual(typeof(BitmapImage), result.GetType());
        }
Beispiel #3
0
        private static async void BlurSettingChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            var control = (FadeImage)obj;

            if (control.Source == null)
            {
                return;
            }

            var blurAmount  = control.BlurAmount;
            var blurEnabled = control.IsBlurEnabled;
            var highQuality = control.HighQualityBlur;
            var source      = control.Source;
            var image       = await Task.Factory.StartNew(() =>
            {
                if (source is string str)
                {
                    return(ImageSourceManager.GetImage(str, false));
                }
                else if (source is BitmapLoadProperties props)
                {
                    return(ImageSourceManager.GetImage(props.Source, false, props));
                }
                else
                {
                    return(null);
                }
            });

            if (blurEnabled)
            {
                control.ImageHolder.Effect = new BlurEffect()
                {
                    KernelType    = KernelType.Gaussian,
                    Radius        = blurAmount,
                    RenderingBias = highQuality ? RenderingBias.Quality : RenderingBias.Performance
                };
            }
            else
            {
                control.ImageHolder.Effect = null;
            }

            GC.Collect();

            if (control.currentImage == CurrentImage.Image1)
            {
                control.Image1.Source = image;
            }
            else if (control.currentImage == CurrentImage.Image2)
            {
                control.Image2.Source = image;
            }
            else
            {
                control.Image1.Source = image;
                control.currentImage  = CurrentImage.Image1;
            }
        }
        public void WebTest()
        {
            FileSystem.DeleteDirectory(PlaynitePaths.ImagesCachePath);
            var image  = @"http://playnite.link/applogo.png";
            var result = ImageSourceManager.GetImage(image, false);

            Assert.AreEqual(typeof(BitmapImage), result.GetType());
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return(DependencyProperty.UnsetValue);
            }

            var image = ImageSourceManager.GetImage((string)value, Cached);

            return(image ?? DependencyProperty.UnsetValue);
        }
        public void DatabaseTest()
        {
            var file = Path.Combine(PlaynitePaths.ProgramPath, "Resources", "Images", "applogo.png");

            using (var temp = TempDirectory.Create())
            {
                var db = new GameDatabase(temp.TempPath);
                db.OpenDatabase();
                var image = db.AddFile("image.png", File.ReadAllBytes(file), Guid.NewGuid());
                ImageSourceManager.SetDatabase(db);
                var result = ImageSourceManager.GetImage(image, false);
                Assert.AreEqual(typeof(BitmapImage), result.GetType());
            }
        }
Beispiel #7
0
        private static async void BlurSettingChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            var control = (FadeImage)obj;

            if (control.Source.IsNullOrEmpty())
            {
                return;
            }

            var blurAmount  = control.BlurAmount;
            var blurEnabled = control.IsBlurEnabled;
            var source      = control.Source;
            var image       = await Task.Factory.StartNew(() =>
            {
                var tmp = ImageSourceManager.GetImage(source, false);
                if (tmp == null)
                {
                    return(null);
                }

                //if (blurEnabled)
                //{
                //    tmp = new GaussianBlur(tmp.ToBitmap()).Process(blurAmount).ToBitmapImage();
                //}

                return(tmp);
            });

            // GaussianBlur uses quite of lot of memory that's not immediately released.
            GC.Collect();

            if (control.currentImage == CurrentImage.Image1)
            {
                control.Image1.Source = image;
            }
            else if (control.currentImage == CurrentImage.Image2)
            {
                control.Image2.Source = image;
            }
        }
Beispiel #8
0
        private async void LoadNewSource(object newSource, object oldSource)
        {
            var         blurAmount  = BlurAmount;
            var         blurEnabled = IsBlurEnabled;
            var         highQuality = HighQualityBlur;
            BitmapImage image       = null;

            if (newSource?.Equals(currentSource) == true)
            {
                return;
            }

            currentSource = newSource;
            if (newSource != null)
            {
                image = await Task.Factory.StartNew(() =>
                {
                    if (newSource is string str)
                    {
                        return(ImageSourceManager.GetImage(str, false));
                    }
                    else if (newSource is BitmapLoadProperties props)
                    {
                        return(ImageSourceManager.GetImage(props.Source, false, props));
                    }
                    else
                    {
                        return(null);
                    }
                });
            }

            if (blurEnabled)
            {
                if (ImageHolder.Effect == null)
                {
                    ImageHolder.Effect = new BlurEffect()
                    {
                        KernelType    = KernelType.Gaussian,
                        Radius        = blurAmount,
                        RenderingBias = highQuality ? RenderingBias.Quality : RenderingBias.Performance
                    };
                }
            }
            else
            {
                if (ImageHolder.Effect != null)
                {
                    ImageHolder.Effect = null;
                }
            }

            if (AnimationEnabled)
            {
                if (image == null)
                {
                    if (currentImage == CurrentImage.None)
                    {
                        return;
                    }

                    if (currentImage == CurrentImage.Image1)
                    {
                        Image1FadeOut.Begin();
                        BorderDarkenFadeOut.Begin();
                    }
                    else if (currentImage == CurrentImage.Image2)
                    {
                        Image2FadeOut.Begin();
                        BorderDarkenFadeOut.Begin();
                    }

                    currentImage = CurrentImage.None;
                }
                else
                {
                    if (currentImage == CurrentImage.None)
                    {
                        Image1FadeOut.Stop();
                        Image1.Source = image;
                        Image1FadeIn.Begin();
                        BorderDarken.Opacity = 1;
                        BorderDarkenFadeOut.Stop();
                        currentImage = CurrentImage.Image1;
                    }
                    else if (currentImage == CurrentImage.Image1)
                    {
                        Image2FadeOut.Stop();
                        Image2.Source = image;
                        Image2FadeIn.Begin();
                        Image1FadeOut.Begin();
                        BorderDarken.Opacity = 1;
                        BorderDarkenFadeOut.Stop();
                        currentImage = CurrentImage.Image2;
                    }
                    else if (currentImage == CurrentImage.Image2)
                    {
                        Image1FadeOut.Stop();
                        Image1.Source = image;
                        Image1FadeIn.Begin();
                        Image2FadeOut.Begin();
                        BorderDarken.Opacity = 1;
                        BorderDarkenFadeOut.Stop();
                        currentImage = CurrentImage.Image1;
                    }
                }
            }
            else
            {
                if (currentImage == CurrentImage.Image1)
                {
                    Image1.Source = image;
                }
                else if (currentImage == CurrentImage.Image2)
                {
                    Image2.Source = image;
                }
                else
                {
                    Image1.Source = image;
                    currentImage  = CurrentImage.Image1;
                }
            }
        }
Beispiel #9
0
        private async void LoadNewSource(string newSource, string oldSource)
        {
            var         blurAmount  = BlurAmount;
            var         blurEnabled = IsBlurEnabled;
            var         highQuality = HighQualityBlur;
            BitmapImage image       = null;

            if (newSource == currentSource)
            {
                return;
            }

            currentSource = newSource;
            if (!newSource.IsNullOrEmpty())
            {
                image = await Task.Factory.StartNew(() =>
                {
                    return(ImageSourceManager.GetImage(newSource, false));
                });
            }

            if (blurEnabled)
            {
                if (ImageHolder.Effect == null)
                {
                    ImageHolder.Effect = new BlurEffect()
                    {
                        KernelType    = KernelType.Gaussian,
                        Radius        = blurAmount,
                        RenderingBias = highQuality ? RenderingBias.Quality : RenderingBias.Performance
                    };
                }
            }
            else
            {
                if (ImageHolder.Effect != null)
                {
                    ImageHolder.Effect = null;
                }
            }

            GC.Collect();

            if (image == null)
            {
                if (currentImage == CurrentImage.None)
                {
                    return;
                }

                if (currentImage == CurrentImage.Image1)
                {
                    Image1FadeOut.Begin();
                    BorderDarkenFadeOut.Begin();
                }
                else if (currentImage == CurrentImage.Image2)
                {
                    Image2FadeOut.Begin();
                    BorderDarkenFadeOut.Begin();
                }

                currentImage = CurrentImage.None;
            }
            else
            {
                if (currentImage == CurrentImage.None)
                {
                    Image1FadeOut.Stop();
                    Image1.Source = image;
                    Image1FadeIn.Begin();
                    BorderDarken.Opacity = 1;
                    BorderDarkenFadeOut.Stop();
                    currentImage = CurrentImage.Image1;
                }
                else if (currentImage == CurrentImage.Image1)
                {
                    Image2FadeOut.Stop();
                    Image2.Source = image;
                    Image2FadeIn.Begin();
                    Image1FadeOut.Begin();
                    BorderDarken.Opacity = 1;
                    BorderDarkenFadeOut.Stop();
                    currentImage = CurrentImage.Image2;
                }
                else if (currentImage == CurrentImage.Image2)
                {
                    Image1FadeOut.Stop();
                    Image1.Source = image;
                    Image1FadeIn.Begin();
                    Image2FadeOut.Begin();
                    BorderDarken.Opacity = 1;
                    BorderDarkenFadeOut.Stop();
                    currentImage = CurrentImage.Image1;
                }
            }
        }
Beispiel #10
0
        private async void LoadNewSource(string newSource, string oldSource)
        {
            var         blurAmount  = BlurAmount;
            var         blurEnabled = IsBlurEnabled;
            BitmapImage image       = null;

            if (!newSource.IsNullOrEmpty())
            {
                image = await Task.Factory.StartNew(() =>
                {
                    var tmp = ImageSourceManager.GetImage(newSource, false);
                    if (tmp == null)
                    {
                        return(null);
                    }

                    //if (blurEnabled)
                    //{
                    //    tmp = new GaussianBlur(tmp.ToBitmap()).Process(blurAmount).ToBitmapImage();

                    //}
                    return(tmp);
                });
            }

            if (blurEnabled)
            {
                // GaussianBlur uses quite of lot of memory that's not immediately released.
                GC.Collect();
            }

            if (image == null)
            {
                if (currentImage == CurrentImage.None)
                {
                    return;
                }

                if (currentImage == CurrentImage.Image1)
                {
                    Image1FadeOut.Begin();
                    BorderDarkenFadeOut.Begin();
                }
                else if (currentImage == CurrentImage.Image2)
                {
                    Image2FadeOut.Begin();
                    BorderDarkenFadeOut.Begin();
                }

                currentImage = CurrentImage.None;
            }
            else
            {
                if (currentImage == CurrentImage.None)
                {
                    Image1FadeOut.Stop();
                    Image1.Source = image;
                    Image1FadeIn.Begin();
                    BorderDarken.Opacity = 1;
                    BorderDarkenFadeOut.Stop();
                    currentImage = CurrentImage.Image1;
                }
                else if (currentImage == CurrentImage.Image1)
                {
                    Image2FadeOut.Stop();
                    Image2.Source = image;
                    Image2FadeIn.Begin();
                    Image1FadeOut.Begin();
                    BorderDarken.Opacity = 1;
                    BorderDarkenFadeOut.Stop();
                    currentImage = CurrentImage.Image2;
                }
                else if (currentImage == CurrentImage.Image2)
                {
                    Image1FadeOut.Stop();
                    Image1.Source = image;
                    Image1FadeIn.Begin();
                    Image2FadeOut.Begin();
                    BorderDarken.Opacity = 1;
                    BorderDarkenFadeOut.Stop();
                    currentImage = CurrentImage.Image1;
                }
            }
        }