Пример #1
0
        /// <summary>
        /// Converts RGB to HSL.
        /// </summary>
        /// <param name="RGB">Color to calculate.</param>
        /// <returns></returns>
        public static HSL RGBToHSL(Color RGB)
        {
            HSL localHSL = new HSL();

            double varR = Convert.ToDouble(RGB.R) / 255.0d;
            double varG = Convert.ToDouble(RGB.G) / 255.0d;
            double varB = Convert.ToDouble(RGB.B) / 255.0d;

            double minVal = Math.Min(Math.Min(varR, varG), varB);//Min. value of RGB
            double maxVal = Math.Max(Math.Max(varR, varG), varB);//Max. value of RGB
            double maxDel = maxVal - minVal;//Delta RGB value

            localHSL.L = (maxVal + minVal) / 2.0d;

            if (maxDel == 0.0d)                     //This is a gray, no chroma...
            {
                localHSL.H = 0.0d;                  //HSL results from 0 to 1
                localHSL.S = 0.0d;
            }
            else                                    //Chromatic data...
            {
                if (localHSL.L < 0.5d)
                    localHSL.S = maxDel / (maxVal + minVal);
                else
                    localHSL.S = maxDel / (2.0d - maxVal - minVal);


                double delR = (((maxVal - varR) / 6.0d) + (maxDel / 2.0d)) / maxDel;
                double delG = (((maxVal - varG) / 6.0d) + (maxDel / 2.0d)) / maxDel;
                double delB = (((maxVal - varB) / 6.0d) + (maxDel / 2.0d)) / maxDel;

                if (varR == maxVal)
                    localHSL.H = delB - delG;
                else if (varG == maxVal)
                    localHSL.H = (1.0d / 3.0d) + delR - delB;
                else if (varB == maxVal)
                    localHSL.H = (2.0d / 3.0d) + delG - delR;


                if (localHSL.H < 0.0d)  //Getting Hue between 0 and 1.
                    localHSL.H += 1.0d;
                if (localHSL.H > 1.0d)
                    localHSL.H -= 1.0d;

            }


            return localHSL;
        }
Пример #2
0
        /// <summary>
        /// Returns the complementary color of the original color.
        /// </summary>
        /// <param name="_originalColor">Original color that is going to be calculated.</param>
        /// <returns></returns>
        public static Color GetComplementaryColor(Color _originalColor)
        {
            if (_originalColor.ToArgb() == Color.White.ToArgb())
            {
                return(Color.Black);
            }

            if (_originalColor.ToArgb() == Color.Black.ToArgb())
            {
                return(Color.White);
            }


            HSL newHSL = RGBToHSL(_originalColor);

            newHSL = calculateTheOppositeHue(newHSL);
            Color newColor = HSLToRGB(newHSL);

            return(newColor);
        }
Пример #3
0
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            labelState.Text = e.Location.X.ToString() + " , " + e.Location.Y.ToString();

            if (isDrawing)
            {
                pictureBox1.Refresh();
                Color newColor = Color.FromArgb(125, Color.Gray);

                Control control = (Control)sender;
                formGraphics = control.CreateGraphics();
                formGraphics.FillRectangle(new SolidBrush(newColor), theRectangle);
                formGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                theRectangle.X             = startpoint.X;
                theRectangle.Y             = startpoint.Y;
                theRectangle.Height        = e.Y - startpoint.Y;
                theRectangle.Width         = e.X - startpoint.X;

                fontSize = 96f;
                SizeF stringSize = formGraphics.MeasureString(DateTime.Now.ToShortTimeString(), new Font(font.Name, fontSize));

                if (theRectangle.Width > 15 && theRectangle.Height > 15)
                {
                    while (stringSize.Width > theRectangle.Width || stringSize.Height > theRectangle.Height)
                    {
                        stringSize = formGraphics.MeasureString(DateTime.Now.ToShortTimeString(), new Font(font.Name, fontSize));
                        fontSize  -= 0.05f;
                    }

                    System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                    path.AddString(DateTime.Now.ToShortTimeString(), font.FontFamily, (int)font.Style, fontSize, theRectangle, new StringFormat());
                    formGraphics.DrawPath(new Pen(HSL.GetComplementaryColor(color), 3f), path);
                    formGraphics.FillPath(new SolidBrush(Color.FromArgb(255, color)), path);

                    Settings.ChangeSetting(Settings.settings.fontSize, fontSize.ToString());
                    Wallpaper.fontSize = this.fontSize;
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Bakes the current time on the original wallpaper and returns the path of the baked wallpaper.
        /// </summary>
        /// <param name="originalWallpaperPath">The full path of the original wallpaper.</param>
        /// <returns></returns>
        public static string BurnNewWallpaper(string originalWallpaperPath)
        {
            Image    wallpaper      = Image.FromFile(originalWallpaperPath);
            Bitmap   bufferBtmp     = new Bitmap(wallpaper);
            Graphics wallpaperGraph = Graphics.FromImage(bufferBtmp);

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

            wallpaperGraph.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            wallpaperGraph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
            path.FillMode = System.Drawing.Drawing2D.FillMode.Winding;

            path.AddString(DateTime.Now.ToShortTimeString(), font.FontFamily, (int)font.Style, (float)(fontSize * Convert.ToDouble(wallpaper.Width) / Convert.ToDouble(pictureBoxRectangle.Width)), CalculateTheRelativePoint(), new StringFormat());
            wallpaperGraph.DrawPath(new Pen(HSL.GetComplementaryColor(color), 3f), path);
            wallpaperGraph.FillPath(new SolidBrush(Color.FromArgb(255, color)), path);
            BurntWallpaperPath = Settings.rootDirectory + "\\wallpaper.png";

            bufferBtmp.Save(BurntWallpaperPath);
            bufferBtmp.Dispose();
            wallpaper.Dispose();
            wallpaperGraph.Dispose();

            return(BurntWallpaperPath);
        }
Пример #5
0
        /// <summary>
        /// Converts HSL to RGB.
        /// </summary>
        /// <param name="hsl">HSL that will be converted to RGB.</param>
        /// <returns></returns>
        public static Color HSLToRGB(HSL hsl)
        {
            double R;
            double B;
            double G;

            double var_1;
            double var_2;

            if (hsl.S == 0.0d)                       //HSL from 0 to 1
            {
                R = hsl.L * 255.0d;                  //RGB results from 0 to 255
                G = hsl.L * 255.0d;
                B = hsl.L * 255.0d;
            }
            else
            {
                if (hsl.L < 0.5d)
                {
                    var_2 = hsl.L * (1.0d + hsl.S);
                }
                else
                {
                    var_2 = (hsl.L + hsl.S) - (hsl.S * hsl.L);
                }

                var_1 = 2.0d * hsl.L - var_2;

                R = 255.0d * HueToRGB(var_1, var_2, hsl.H + (1.0d / 3.0d));
                G = 255.0d * HueToRGB(var_1, var_2, hsl.H);
                B = 255.0d * HueToRGB(var_1, var_2, hsl.H - (1.0d / 3.0d));
            }
            Color cl = Color.FromArgb(Convert.ToInt32(R), Convert.ToInt32(G), Convert.ToInt32(B));

            return(cl);
        }
Пример #6
0
        /// <summary>
        /// Converts HSL to RGB.
        /// </summary>
        /// <param name="hsl">HSL that will be converted to RGB.</param>
        /// <returns></returns>
        public static Color HSLToRGB(HSL hsl)
        {
            double R;
            double B;
            double G;

            double var_1;
            double var_2;

            if (hsl.S == 0.0d)                       //HSL from 0 to 1
            {
                R = hsl.L * 255.0d;                      //RGB results from 0 to 255
                G = hsl.L * 255.0d;
                B = hsl.L * 255.0d;
            }
            else
            {
                if (hsl.L < 0.5d)
                    var_2 = hsl.L * (1.0d + hsl.S);
                else
                    var_2 = (hsl.L + hsl.S) - (hsl.S * hsl.L);

                var_1 = 2.0d * hsl.L - var_2;

                R = 255.0d * HueToRGB(var_1, var_2, hsl.H + (1.0d / 3.0d));
                G = 255.0d * HueToRGB(var_1, var_2, hsl.H);
                B = 255.0d * HueToRGB(var_1, var_2, hsl.H - (1.0d / 3.0d));
            }
            Color cl = Color.FromArgb(Convert.ToInt32(R), Convert.ToInt32(G), Convert.ToInt32(B));

            return cl;
        }
Пример #7
0
        /// <summary>
        /// Takes normal HSL and rotates the Hue by 180 degrees and returns the new HSL value.
        /// </summary>
        /// <param name="normalHSL">HSL to calculate.</param>
        /// <returns></returns>
        public static HSL calculateTheOppositeHue(HSL normalHSL)
        {
            HSL newHue = normalHSL;

            newHue.H = (newHue.H + 0.333d) % 1.0d;

            return newHue;
        }
Пример #8
0
        /// <summary>
        /// Converts RGB to HSL.
        /// </summary>
        /// <param name="RGB">Color to calculate.</param>
        /// <returns></returns>
        public static HSL RGBToHSL(Color RGB)
        {
            HSL localHSL = new HSL();

            double varR = Convert.ToDouble(RGB.R) / 255.0d;
            double varG = Convert.ToDouble(RGB.G) / 255.0d;
            double varB = Convert.ToDouble(RGB.B) / 255.0d;

            double minVal = Math.Min(Math.Min(varR, varG), varB); //Min. value of RGB
            double maxVal = Math.Max(Math.Max(varR, varG), varB); //Max. value of RGB
            double maxDel = maxVal - minVal;                      //Delta RGB value

            localHSL.L = (maxVal + minVal) / 2.0d;

            if (maxDel == 0.0d)                     //This is a gray, no chroma...
            {
                localHSL.H = 0.0d;                  //HSL results from 0 to 1
                localHSL.S = 0.0d;
            }
            else                                    //Chromatic data...
            {
                if (localHSL.L < 0.5d)
                {
                    localHSL.S = maxDel / (maxVal + minVal);
                }
                else
                {
                    localHSL.S = maxDel / (2.0d - maxVal - minVal);
                }


                double delR = (((maxVal - varR) / 6.0d) + (maxDel / 2.0d)) / maxDel;
                double delG = (((maxVal - varG) / 6.0d) + (maxDel / 2.0d)) / maxDel;
                double delB = (((maxVal - varB) / 6.0d) + (maxDel / 2.0d)) / maxDel;

                if (varR == maxVal)
                {
                    localHSL.H = delB - delG;
                }
                else if (varG == maxVal)
                {
                    localHSL.H = (1.0d / 3.0d) + delR - delB;
                }
                else if (varB == maxVal)
                {
                    localHSL.H = (2.0d / 3.0d) + delG - delR;
                }


                if (localHSL.H < 0.0d)  //Getting Hue between 0 and 1.
                {
                    localHSL.H += 1.0d;
                }
                if (localHSL.H > 1.0d)
                {
                    localHSL.H -= 1.0d;
                }
            }


            return(localHSL);
        }