/// <summary>
 /// Returns the proper <see cref="T:Xamarin.Forms.Platform.iOS.IImageSourceHandler"/> 
 /// based on the type of <see cref="T:Xamarin.Forms.ImageSource"/> provided.
 /// </summary>
 /// <param name="source">The <see cref="T:Xamarin.Forms.ImageSource"/> to get the handler for.</param>
 /// <returns>
 /// The needed handler.
 /// </returns>
 private static IImageSourceHandler GetHandler(ImageSource source)
 {
     var imageSourceHandler = (IImageSourceHandler)null;
     if(source is UriImageSource)
         imageSourceHandler = new ImageLoaderSourceHandler();
     else if(source is FileImageSource)
         imageSourceHandler = new FileImageSourceHandler();
     else if(source is StreamImageSource)
         imageSourceHandler = new StreamImagesourceHandler();
     return imageSourceHandler;
 }
 public static IImageSourceHandler GetHandler(this ImageSource source)
 {
     IImageSourceHandler returnValue = null;
     if (source is UriImageSource)
         returnValue = new ImageLoaderSourceHandler();
     else if (source is FileImageSource)
         returnValue = new FileImageSourceHandler();
     else if (source is StreamImageSource)
         returnValue = new StreamImagesourceHandler();
     return returnValue;
 }
 /// <summary>
 /// Returns the proper <see cref="IImageSourceHandler"/> based on the type of <see cref="ImageSource"/> provided.
 /// </summary>
 /// <param name="source">The <see cref="ImageSource"/> to get the handler for.</param>
 /// <returns>The needed handler.</returns>
 private static IImageSourceHandler GetHandler(ImageSource source)
 {
     IImageSourceHandler returnValue = null;
     if (source is UriImageSource) {
         returnValue = new ImageLoaderSourceHandler ();
     } else if (source is FileImageSource) {
         returnValue = new FileImageSourceHandler ();
     } else if (source is StreamImageSource) {
         returnValue = new StreamImagesourceHandler ();
     }
     return returnValue;
 }
Exemplo n.º 4
0
        public async Task<bool> SaveImage(ImageSource img, string imageName)
        {
            var render = new StreamImagesourceHandler();

            image = await render.LoadImageAsync(img);

            var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            var nomeImagem = Path.Combine(path, imageName);

            NSData imgData = image.AsJPEG();
            NSError erro = null;

            return imgData.Save(nomeImagem, false, out erro);
        }
Exemplo n.º 5
0
		public async void SavePictureToDisk (ImageSource imgSrc, int Id)
		{
			var renderer = new StreamImagesourceHandler ();
			var photo = await renderer.LoadImageAsync (imgSrc);
			var documentsDirectory = Environment.GetFolderPath
				(Environment.SpecialFolder.Personal);
			string jpgFilename = System.IO.Path.Combine (
				documentsDirectory, Id.ToString () + ".jpg");
			NSData imgData = photo.AsJPEG ();
			NSError err = null;
			if (imgData.Save (jpgFilename, false, out err)) {
				Console.WriteLine ("saved as " + jpgFilename);
			} else {
				Console.WriteLine ("NOT saved as " + jpgFilename +
					" because" + err.LocalizedDescription);
			}

		}
Exemplo n.º 6
0
        private static IImageSourceHandler GetHandler(ImageSource source)
        {
            IImageSourceHandler returnValue = null;

            if (source is UriImageSource)
            {
                returnValue = new ImageLoaderSourceHandler();
            }
            else if (source is FileImageSource)
            {
                returnValue = new FileImageSourceHandler();
            }
            else if (source is StreamImageSource)
            {
                returnValue = new StreamImagesourceHandler();
            }
            return(returnValue);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Helper method to initialize the respective <see cref="IImageSourceHandler"/> to native <see cref="ImageView"/> using <see cref="SfImage.Source"/> property.
        /// </summary>
        /// <param name="source">Represents the <see cref="ImageSource"/>.</param>
        /// <returns>Returns the <see cref="IImageSourceHandler"/> based on <see cref="ImageSource"/>.</returns>
        private IImageSourceHandler GetHandler(ImageSource source)
        {
            IImageSourceHandler sourcehandler = null;

            if (source is UriImageSource)
            {
                sourcehandler = new ImageLoaderSourceHandler();
            }
            else if (source is FileImageSource)
            {
                sourcehandler = new FileImageSourceHandler();
            }
            else if (source is StreamImageSource)
            {
                sourcehandler = new StreamImagesourceHandler();
            }
            return(sourcehandler);
        }
        public static Task <UIImage> ToUIImage(this ImageSource imageSource)
        {
            IImageSourceHandler handler = null;

            if (imageSource is UriImageSource)
            {
                handler = new ImageLoaderSourceHandler();
            }
            else if (imageSource is FileImageSource)
            {
                handler = new FileImageSourceHandler();
            }
            else if (imageSource is StreamImageSource)
            {
                handler = new StreamImagesourceHandler();
            }
            return(handler.LoadImageAsync(imageSource));
        }
        // ReSharper disable once UnusedMember.Local
        private async Task <ImageSource> RotateImageToPortrait(ImageSource imgSource)
        {
            var imagesourceHandler = new StreamImagesourceHandler();
            var photoTask          = imagesourceHandler.LoadImageAsync(imgSource, _context);

            var photo = await photoTask;

            var matrix = new Matrix();

            matrix.PreRotate(-90);
            photo = Bitmap.CreateBitmap(photo, 0, 0, photo.Width, photo.Height, matrix, false);
            matrix.Dispose();

            var stream = new MemoryStream();

            photo.Compress(Bitmap.CompressFormat.Jpeg, 50, stream);
            stream.Seek(0L, SeekOrigin.Begin);
            return(ImageSource.FromStream(() => stream));
        }
Exemplo n.º 10
0
        public async void SavePictureToDisk(ImageSource imgSrc, string id)
        {
            var renderer = new StreamImagesourceHandler();
            var photo    = await renderer.LoadImageAsync(imgSrc);

            var     documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            string  jpgFilename        = System.IO.Path.Combine(documentsDirectory, id + ".jpg");
            NSData  imgData            = photo.AsJPEG();
            NSError err = null;

            if (imgData.Save(jpgFilename, false, out err))
            {
                Console.WriteLine("saved as " + jpgFilename);
            }
            else
            {
                Console.WriteLine("NOT saved as " + jpgFilename + " because" + err.LocalizedDescription);
            }
        }
		public static IImageSourceHandler GetHandler (this ImageSource source)
		{
			//Image source handler to return
			IImageSourceHandler returnValue = null;
			//check the specific source type and return the correct image source handler
			if (source is UriImageSource)
			{
				returnValue = new ImageLoaderSourceHandler();
			}
			else if (source is FileImageSource)
			{
				returnValue = new FileImageSourceHandler();
			}
			else if (source is StreamImageSource)
			{
				returnValue = new StreamImagesourceHandler();
			}
			return returnValue;
		}
Exemplo n.º 12
0
        public async Task <Stream> ToJpegStreamAsync(ImageSource imageSource)
        {
            if (imageSource == null)
            {
                throw new ArgumentNullException(nameof(imageSource));
            }

            if (imageSource is StreamImageSource)
            {
                var imageStream = new StreamImagesourceHandler();
                var image       = await imageStream.LoadImageAsync(imageSource);

                return(image.AsJPEG().AsStream());
            }
            else
            {
                throw new InvalidOperationException($"The type of the given imageSource is '{imageSource.GetType().Name}', but 'StreamImageSource' were expected.");
            }
        }
        private Task <Bitmap> GetImageFromImageSourceAsync(ImageSource imageSource)
        {
            IImageSourceHandler handler = null;

            if (imageSource is FileImageSource)
            {
                handler = new FileImageSourceHandler();
            }
            else if (imageSource is StreamImageSource)
            {
                handler = new StreamImagesourceHandler();
            }
            else if (imageSource is UriImageSource)
            {
                handler = new ImageLoaderSourceHandler();
            }

            return(handler?.LoadImageAsync(imageSource, _context));
        }
Exemplo n.º 14
0
        private async void SetSource(System.Windows.Controls.Image image)
        {
            IImageSourceHandler handler;
            var source = (this.Element as BlurImageView).Source;

            if (source is FileImageSource)
            {
                handler = new FileImageSourceHandler();
            }
            else if (source is StreamImageSource)
            {
                handler = new StreamImagesourceHandler(); // sic
            }
            else if (source is UriImageSource)
            {
                handler = new ImageLoaderSourceHandler(); // sic
            }
            else
            {
                throw new NotImplementedException();
            }

            System.Windows.Media.ImageSource imagesource;
            try
            {
                imagesource = await handler.LoadImageAsync(source, new CancellationToken());
            }
            catch (TaskCanceledException ex)
            {
                imagesource = (System.Windows.Media.ImageSource)null;
            }

            // Blur
            if (imagesource is BitmapImage)
            {
                var bmpImage = imagesource as BitmapImage;
                var wr       = new WriteableBitmap(bmpImage);
                BoxBlurHorizontal(wr, 40);
                BoxBlurVertical(wr, 40);
                image.Source = wr;
            }
        }
Exemplo n.º 15
0
        public static async Task <UIImage> GetUIImage(this ImageSource imageSource, CancellationToken cancellationToken)
        {
            try
            {
                IImageSourceHandler handler = null;

                if (imageSource is FileImageSource)
                {
                    handler = new FileImageSourceHandler();
                }
                else if (imageSource is StreamImageSource)
                {
                    handler = new StreamImagesourceHandler();
                }
                else if (imageSource is UriImageSource)
                {
                    handler = new ImageLoaderSourceHandler();
                }
                else
                {
                    throw new NotImplementedException("Image source type is not supported.");
                }

                using (var image = await handler.LoadImageAsync(imageSource, cancellationToken, (float)UIScreen.MainScreen.Scale))
                //using (var image = await handler.LoadImageAsync(imageSource))
                {
                    if (image == null)
                    {
                        return(null);
                    }

                    UIGraphics.BeginImageContext(image.Size);
                    image.Draw(new CGRect(0, 0, image.Size.Width, image.Size.Height));
                    return(UIGraphics.GetImageFromCurrentImageContext());
                }
                //return handler.LoadImageAsync (imageSource, cancellationToken, (float)UIScreen.MainScreen.Scale);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 16
0
        public async Task SaveImage(ImageSource _imageSource, string _filename)
        {
            var renderer = new StreamImagesourceHandler();

            var photo = await renderer.LoadImageAsync(_imageSource);

            string jpgFilename = GetLocalImageFilename(_filename);

            NSData  imgData = photo.AsJPEG();
            NSError err     = null;

            if (imgData.Save(jpgFilename, false, out err))
            {
                Console.WriteLine("saved as " + jpgFilename);
            }
            else
            {
                Console.WriteLine("NOT saved as " + jpgFilename + " because" + err.LocalizedDescription);
            }
        }
    public static IImageSourceHandler GetHandler(this ImageSource source)
    {
        IImageSourceHandler returnValue = null;

        switch (source)
        {
        case UriImageSource _:
            returnValue = new ImageLoaderSourceHandler();
            break;

        case FileImageSource _:
            returnValue = new FileImageSourceHandler();
            break;

        case StreamImageSource _:
            returnValue = new StreamImagesourceHandler();
            break;
        }

        return(returnValue);
    }
Exemplo n.º 18
0
        public async Task<bool> SaveImage(ImageSource img, string imageName)
        {
            try
            {
                var renderer = new StreamImagesourceHandler();
                imagem = await renderer.LoadImageAsync(img, Forms.Context);

                var documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                string pngPath = System.IO.Path.Combine(documentsDirectory, imageName + ".png");

                using (System.IO.FileStream fs = new System.IO.FileStream(pngPath, System.IO.FileMode.OpenOrCreate))
                {
                    imagem.Compress(Bitmap.CompressFormat.Png, 100, fs);
                    return await Task.FromResult<bool>(true);
                }
            }
            catch (Exception)
            {
                return await Task.FromResult<bool>(false);
            }
        }
Exemplo n.º 19
0
        public async void ShareContent(string subject, string message, ImageSource image)
        {
            var intent = new Intent(Intent.ActionSend);

            intent.PutExtra(Intent.ExtraText, message);
            intent.SetType("image/png");

            var handler = new StreamImagesourceHandler();
            var bitmap  = await handler.LoadImageAsync(image, this);

            var path = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads
                                                                                + Java.IO.File.Separator + "mydiagram.png");

            using (System.IO.FileStream os = new System.IO.FileStream(path.AbsolutePath, System.IO.FileMode.Create))
            {
                bitmap.Compress(Bitmap.CompressFormat.Png, 100, os);
            }

            intent.PutExtra(Intent.ExtraStream, Android.Net.Uri.FromFile(path));
            CrossCurrentActivity.Current.Activity.StartActivity(Intent.CreateChooser(intent, "Share Image"));
        }
Exemplo n.º 20
0
        public static IImageSourceHandler GetDefaultHandler(this ImageSource source)
        {
            IImageSourceHandler handler = null;

            if (source is UriImageSource)
            {
                handler = new ImageLoaderSourceHandler();
            }
            else if (source is FileImageSource)
            {
                handler = new FileImageSourceHandler();
            }
            else if (source is StreamImageSource)
            {
                handler = new StreamImagesourceHandler();
            }
            else if (source is FontImageSource)
            {
                handler = new FontImageSourceHandler();
            }
            return(handler);
        }
        private async Task <UIImage> LoadImageFromImageSource(ImageSource imageSource)
        {
            IImageSourceHandler handler;

            if (imageSource is FileImageSource)
            {
                handler = new FileImageSourceHandler();
            }
            else if (imageSource is StreamImageSource)
            {
                handler = new StreamImagesourceHandler();
            }
            else if (imageSource is UriImageSource)
            {
                handler = new ImageLoaderSourceHandler();
            }
            else
            {
                return(null);
            }

            return(await handler.LoadImageAsync(imageSource));
        }
Exemplo n.º 22
0
        Task <UIImage> GetImage(ImageSource imageSource)
        {
            IImageSourceHandler handler;

            if (imageSource is FileImageSource)
            {
                handler = new FileImageSourceHandler();
            }
            else if (imageSource is StreamImageSource)
            {
                handler = new StreamImagesourceHandler(); // sic
            }
            else if (imageSource is UriImageSource)
            {
                handler = new ImageLoaderSourceHandler(); // sic
            }
            else
            {
                throw new NotImplementedException();
            }

            return(handler.LoadImageAsync(imageSource));
        }
        public static Task <Bitmap> GetImage(this ImageSource imageSource)
        {
            IImageSourceHandler handler = null;

            if (imageSource is FileImageSource)
            {
                handler = new FileImageSourceHandler();
            }
            else if (imageSource is StreamImageSource)
            {
                handler = new StreamImagesourceHandler();
            }
            else if (imageSource is UriImageSource)
            {
                handler = new ImageLoaderSourceHandler();
            }
            else
            {
                throw new NotImplementedException("Image source type is not supported.");
            }

            return(handler.LoadImageAsync(imageSource, Forms.Context));
        }
Exemplo n.º 24
0
        public static IImageSourceHandler GetImageSourceHandler(ImageSource source)
        {
            IImageSourceHandler sourceHandler = null;

            if (source is UriImageSource)
            {
                sourceHandler = new ImageLoaderSourceHandler();
            }
            else if (source is FileImageSource)
            {
                sourceHandler = new FileImageSourceHandler();
            }
            else if (source is StreamImageSource)
            {
                sourceHandler = new StreamImagesourceHandler();
            }
            else if (source is FontImageSource)
            {
                sourceHandler = new FontImageSourceHandler();
            }

            return(sourceHandler);
        }
Exemplo n.º 25
0
        private async Task <Bitmap> GetImageFromImageSource(ImageSource imageSource)
        {
            IImageSourceHandler handler;

            if (imageSource is FileImageSource)
            {
                handler = new FileImageSourceHandler();
            }
            else if (imageSource is StreamImageSource)
            {
                handler = new StreamImagesourceHandler(); // sic
            }
            else if (imageSource is UriImageSource)
            {
                handler = new ImageLoaderSourceHandler(); // sic
            }
            else
            {
                throw new NotImplementedException();
            }

            return(await handler.LoadImageAsync(imageSource, this.Control.Context));
        }
Exemplo n.º 26
0
        private async Task <Bitmap> LoadBitmapFromImageSource(Context context, ImageSource imageSource)
        {
            IImageSourceHandler handler;

            if (imageSource is FileImageSource)
            {
                handler = new FileImageSourceHandler();
            }
            else if (imageSource is StreamImageSource)
            {
                handler = new StreamImagesourceHandler();
            }
            else if (imageSource is UriImageSource)
            {
                handler = new ImageLoaderSourceHandler();
            }
            else
            {
                return(null);
            }

            return(await handler.LoadImageAsync(imageSource, context));
        }
        private static IImageSourceHandler GetHandler(ImageSource source)
        {
            IImageSourceHandler returnValue = null;

            switch (source)
            {
            case UriImageSource _:
                returnValue = new ImageLoaderSourceHandler();
                break;

            case FileImageSource _:
                returnValue = new FileImageSourceHandler();
                break;

            case StreamImageSource _:
                returnValue = new StreamImagesourceHandler();
                break;

            case SKBitmapImageSource _:
                returnValue = new SKImageSourceHandler();
                break;
            }
            return(returnValue);
        }
        private async Task <Bitmap> GetImageFromImageSource(ImageSource imageSource, Context context)
        {
            IImageSourceHandler handler;
            bool isUriImage = false;

            if (imageSource is FileImageSource)
            {
                handler = new FileImageSourceHandler();
            }
            else if (imageSource is StreamImageSource)
            {
                handler = new StreamImagesourceHandler(); // sic
            }
            else if (imageSource is UriImageSource)
            {
                isUriImage = true;
                handler    = new ImageLoaderSourceHandler(); // sic
            }
            else
            {
                throw new NotImplementedException();
            }

            Bitmap originalBitmap = null;

            if (isUriImage)
            {
                var uri = Element.Source.GetValue(UriImageSource.UriProperty) as Uri;

                if (imageDownloader.HasLocallyCachedCopy(uri))
                {
                    var bitmap = imageDownloader.GetImage(uri);
                    if (BaseControl.ImagePlaceholder != null && bitmap == null)
                    {
                    }
                    else
                    {
                        originalBitmap = bitmap;
                    }
                }
                else
                {
                    await imageDownloader.GetImageAsync(uri).ContinueWith(t =>
                    {
                        if (t != null)
                        {
                            if (!t.IsFaulted)
                            {
                                //imageDownloader.RemoveDownloadProgress(uri);
                                if (BaseControl == null)
                                {
                                    return;
                                }

                                if (BaseControl.ImagePlaceholder != null && t.Result == null)
                                {
                                    return;
                                }

                                originalBitmap = t.Result;
                            }
                        }
                    }, TaskScheduler.FromCurrentSynchronizationContext());
                }
            }
            else
            {
                originalBitmap = await handler.LoadImageAsync(imageSource, context);
            }



            return(originalBitmap);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected async override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (Control == null)
            {
                return;
            }



            var min = Math.Min(Element.Width, Element.Height) / 2.0f;

            if (min <= 0)
            {
                return;
            }

            try
            {
                Control.Width  = Element.Width;
                Control.Height = Element.Height;

                // Fill background color
                var color = ((CircleImage)Element).FillColor;
                Control.Fill = new SolidColorBrush(Windows.UI.Color.FromArgb(
                                                       (byte)(color.A * 255),
                                                       (byte)(color.R * 255),
                                                       (byte)(color.G * 255),
                                                       (byte)(color.B * 255)));

                // Fill stroke
                color = ((CircleImage)Element).BorderColor;
                Control.StrokeThickness = ((CircleImage)Element).BorderThickness;
                Control.Stroke          = new SolidColorBrush(Windows.UI.Color.FromArgb(
                                                                  (byte)(color.A * 255),
                                                                  (byte)(color.R * 255),
                                                                  (byte)(color.G * 255),
                                                                  (byte)(color.B * 255)));

                var force = e.PropertyName == VisualElement.XProperty.PropertyName ||
                            e.PropertyName == VisualElement.YProperty.PropertyName ||
                            e.PropertyName == VisualElement.WidthProperty.PropertyName ||
                            e.PropertyName == VisualElement.HeightProperty.PropertyName ||
                            e.PropertyName == VisualElement.ScaleProperty.PropertyName ||
                            e.PropertyName == VisualElement.TranslationXProperty.PropertyName ||
                            e.PropertyName == VisualElement.TranslationYProperty.PropertyName ||
                            e.PropertyName == VisualElement.RotationYProperty.PropertyName ||
                            e.PropertyName == VisualElement.RotationXProperty.PropertyName ||
                            e.PropertyName == VisualElement.RotationProperty.PropertyName ||
                            e.PropertyName == VisualElement.AnchorXProperty.PropertyName ||
                            e.PropertyName == VisualElement.AnchorYProperty.PropertyName;


                //already set
                if (file == Element.Source && !force)
                {
                    return;
                }

                file = Element.Source;

                BitmapImage bitmapImage = null;

                // Handle file images
                if (file is FileImageSource)
                {
                    var fi       = Element.Source as FileImageSource;
                    var myFile   = System.IO.Path.Combine(Package.Current.InstalledLocation.Path, fi.File);
                    var myFolder = await StorageFolder.GetFolderFromPathAsync(System.IO.Path.GetDirectoryName(myFile));

                    using (Stream s = await myFolder.OpenStreamForReadAsync(System.IO.Path.GetFileName(myFile)))
                    {
                        var memStream = new MemoryStream();
                        await s.CopyToAsync(memStream);

                        memStream.Position = 0;
                        bitmapImage        = new BitmapImage();
                        bitmapImage.SetSource(memStream.AsRandomAccessStream());
                    }
                }
                else if (file is UriImageSource)
                {
                    bitmapImage = new BitmapImage((Element.Source as UriImageSource).Uri);
                }
                else if (file is StreamImageSource)
                {
                    var handler     = new StreamImagesourceHandler();
                    var imageSource = await handler.LoadImageAsync(file);

                    if (imageSource != null)
                    {
                        Control.Fill = new ImageBrush
                        {
                            ImageSource = imageSource,
                            Stretch     = Stretch.UniformToFill,
                        };
                    }
                    return;
                }

                if (bitmapImage != null)
                {
                    Control.Fill = new ImageBrush
                    {
                        ImageSource = bitmapImage,
                        Stretch     = Stretch.UniformToFill,
                    };
                }

                /*var handler = GetHandler(file);
                 * var imageSource = await handler.LoadImageAsync(file);
                 *
                 * if (imageSource != null)
                 * {
                 *  Control.Fill = new ImageBrush
                 *  {
                 *      ImageSource = imageSource,
                 *      Stretch = Stretch.UniformToFill,
                 *  };
                 * }*/
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image, falling back to background color.");
            }
        }
Exemplo n.º 30
0
        public async System.Threading.Tasks.Task <ThemeColors> GetColorAsync(ImageSource imageSource)
        {
            IImageSourceHandler handler;

            ThemeColors themeColors = new ThemeColors();

            if (imageSource is FileImageSource)
            {
                handler = new FileImageSourceHandler();
            }
            else if (imageSource is StreamImageSource)
            {
                handler = new StreamImagesourceHandler(); // sic
            }
            else if (imageSource is UriImageSource)
            {
                handler = new ImageLoaderSourceHandler(); // sic
            }
            else
            {
                return(themeColors);
            }
            var bitmap = await handler.LoadImageAsync(imageSource, Android.App.Application.Context);

            if (bitmap == null)
            {
                return(themeColors);
            }
            Palette.Builder builder = Palette.From(bitmap);
            Palette         palette = builder.Generate();
            Swatch          swatch  = null;

            if (palette.VibrantSwatch != null)
            {
                swatch = palette.VibrantSwatch;
            }
            else if (palette.LightVibrantSwatch != null)
            {
                swatch = palette.LightVibrantSwatch;
            }
            else if (palette.LightMutedSwatch != null)
            {
                swatch = palette.LightMutedSwatch;
            }
            else if (palette.DarkVibrantSwatch != null)
            {
                swatch = palette.DarkVibrantSwatch;
            }
            else if (palette.DarkMutedSwatch != null)
            {
                swatch = palette.DarkMutedSwatch;
            }
            int bgcolor = 0, textcolor = 0, titltcolor = 0;

            if (swatch != null)
            {
                bgcolor    = swatch.Rgb;
                textcolor  = swatch.BodyTextColor;
                titltcolor = swatch.TitleTextColor;
            }
            themeColors.SetColor(bgcolor, textcolor, titltcolor);
            return(themeColors);
        }