Пример #1
0
 private void SuggestColorButton_Click(object sender, EventArgs e)
 {
     if (MediumTilePreview.TileImage != null)
     {
         ColorThiefDotNet.ColorThief colorThief = new ColorThiefDotNet.ColorThief();
         var quantizedColor = colorThief.GetColor((Bitmap)MediumTilePreview.TileImage);
         BackgroundTextBox.Text = quantizedColor.Color.ToHexString();
     }
 }
Пример #2
0
        private void imageColor()
        {
            var    colorThief = new ColorThiefDotNet.ColorThief();
            Bitmap bmp        = new Bitmap(pathSource);

            try
            {
                ColorThiefDotNet.QuantizedColor color = colorThief.GetColor(bmp);
                Color c = Color.FromArgb(color.Color.A, color.Color.R, color.Color.G, color.Color.B);
                ThemeColor.Default.Top    = c;
                ThemeColor.Default.Drawer = c;
                ThemeColor.Default.Panel  = c;
                ThemeColor.Default.Save();
            }
            catch (Exception ex) {}
        }
Пример #3
0
        public static async Task <Color> GetDominantColor(StorageFile file)
        {
            using (var stream = await file.OpenAsync(FileAccessMode.Read))
            {
                try
                {
                    //Create a decoder for the image
                    var decoder = await BitmapDecoder.CreateAsync(stream);

                    var colorThief = new ColorThiefDotNet.ColorThief();
                    var qColor     = await colorThief.GetColor(decoder);

                    //read the color
                    return(Color.FromArgb(qColor.Color.A, qColor.Color.R, qColor.Color.G, qColor.Color.B));
                }
                catch { return((App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush).Color); }
            }
        }
Пример #4
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string file      = "";
            Plane  plane     = new Plane();
            int    n_row     = 0;
            int    n_col     = 0;
            double width     = 0;
            double height    = 0;
            int    precision = 0;

            Bitmap bm = null;
            List <ColorThiefDotNet.Color> palette = null;
            int interval     = 5;
            int paletteCount = 5;

            DA.GetData("File", ref file);
            DA.GetData("Plane", ref plane);
            DA.GetData("Num_Row", ref n_row);
            DA.GetData("Num_Col", ref n_col);
            DA.GetData("Width", ref width);
            DA.GetData("Height", ref height);
            DA.GetData("Precision", ref precision);
            DA.GetData("PaletteCount", ref paletteCount);
            if (precision < 1)
            {
                precision = 1;
            }
            if (precision > 10)
            {
                precision = 10;
            }

            DataTree <Plane>       plns  = new DataTree <Plane>();
            DataTree <Rectangle3d> rects = new DataTree <Rectangle3d>();
            DataTree <GH_Colour>   avgCs = new DataTree <GH_Colour>();
            DataTree <GH_Colour>   matCs = new DataTree <GH_Colour>();
            List <GH_Colour>       pltCs = new List <GH_Colour>();

            try
            {
                bm = new Bitmap(file);
                ColorThiefDotNet.ColorThief ct = new ColorThiefDotNet.ColorThief();
                palette  = ct.GetPalette(bm, paletteCount, 10, false).Select(e => e.Color).ToList();
                interval = (int)Math.Pow((bm.Width * bm.Height) / (n_col * n_row), 0.5) / precision;
                foreach (var c in palette)
                {
                    Color color = Color.FromArgb(c.R, c.G, c.B);
                    pltCs.Add(new GH_Colour(color));
                }
            }
            catch { }

            for (int i = 0; i < n_col; i++)
            {
                for (int j = 0; j < n_row; j++)
                {
                    GH_Path  path = new GH_Path(i);
                    Vector3d tx   = plane.XAxis * i * width;
                    Vector3d ty   = plane.YAxis * j * height;
                    Vector3d t    = tx + ty;
                    Plane    pln  = plane.Clone();
                    pln.Translate(t);
                    plns.Add(pln, path);

                    Rectangle3d rect = new Rectangle3d(pln, width, height);
                    rects.Add(rect, path);

                    if (bm != null)
                    {
                        int x       = (int)(Convert.ToDouble(bm.Width) / n_col * (i + 0.5));
                        int y       = (int)(Convert.ToDouble(bm.Height) / n_row * (j + 0.5));
                        int mWidth  = bm.Width / n_col;
                        int mHeight = bm.Height / n_row;


                        Color     avgColor = GetAveragedColor(bm, x, y, mWidth, mHeight, interval);
                        GH_Colour avgC     = new GH_Colour(avgColor);
                        avgCs.Add(avgC, path);

                        var       tempC    = GetPaletteClosest(palette, avgColor);
                        Color     matColor = Color.FromArgb(tempC.R, tempC.G, tempC.B);
                        GH_Colour matC     = new GH_Colour(matColor);
                        matCs.Add(matC, path);
                    }
                }
            }

            DA.SetDataTree(0, plns);
            DA.SetDataTree(1, rects);
            DA.SetDataTree(2, avgCs);
            DA.SetDataTree(3, matCs);
            DA.SetDataList(4, pltCs);
        }