示例#1
0
        protected async override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var btnFetchImage = FindViewById <Button> (Resource.Id.btnFetchImage);

            btnFetchImage.Click += (sender, e) => {
                var p = new Palette.Builder(bitmapFoundation)
                        .Generate();

                RunOnUiThread(() => SetPalette(p));
            };

            bitmapFoundation = await BitmapFactory.DecodeResourceAsync(Resources, Resource.Drawable.viva);
        }
        public void Colorize(Bitmap bitmap)
        {
            Palette palette = new Palette.Builder(bitmap).Generate();

            ApplyPalette(palette);
        }
		public void Colorize (Bitmap bitmap)
		{
			Palette palette = new Palette.Builder (bitmap).Generate ();
			ApplyPalette (palette);
		}
示例#4
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);
        }