예제 #1
0
        public void ToHsv()
        {
            foreach (HtmlColorSample sample in HtmlColorSamples.All)
            {
                int r = sample.Rgb.Red;
                int g = sample.Rgb.Green;
                int b = sample.Rgb.Blue;

                RgbColor rgb = new RgbColor(r, g, b);

                double h1 = sample.Hsv.Hue / 360d;
                double s1 = sample.Hsv.Saturation;
                double v1 = sample.Hsv.Value;

                ColorUtils.RgbToHsv(r, g, b, out double h2, out double s2, out double l2);
                Assert.AreEqual(h1.ToString("N2"), h2.ToString("N2"), "#1 Hue (" + sample.Name + ")");
                Assert.AreEqual(s1.ToString("N2"), s2.ToString("N2"), "#1 Saturation (" + sample.Name + ")");
                Assert.AreEqual(v1.ToString("N2"), l2.ToString("N2"), "#1 Value (" + sample.Name + ")");

                HsvColor hsv1 = ColorUtils.RgbToHsv(r, g, b);
                Assert.AreEqual(h1.ToString("N2"), hsv1.Hue.ToString("N2"), "#2 Hue (" + sample.Name + ")");
                Assert.AreEqual(s1.ToString("N2"), hsv1.Saturation.ToString("N2"), "#2 Saturation (" + sample.Name + ")");
                Assert.AreEqual(v1.ToString("N2"), hsv1.Value.ToString("N2"), "#2 Value (" + sample.Name + ")");

                HsvColor hsl2 = ColorUtils.RgbToHsv(rgb);
                Assert.AreEqual(h1.ToString("N2"), hsl2.Hue.ToString("N2"), "#3 Hue (" + sample.Name + ")");
                Assert.AreEqual(s1.ToString("N2"), hsl2.Saturation.ToString("N2"), "#3 Saturation (" + sample.Name + ")");
                Assert.AreEqual(v1.ToString("N2"), hsl2.Value.ToString("N2"), "#3 Value (" + sample.Name + ")");

                HsvColor hsl3 = rgb.ToHsv();
                Assert.AreEqual(h1.ToString("N2"), hsl3.Hue.ToString("N2"), "#4 Hue (" + sample.Name + ")");
                Assert.AreEqual(s1.ToString("N2"), hsl3.Saturation.ToString("N2"), "#4 Saturation (" + sample.Name + ")");
                Assert.AreEqual(v1.ToString("N2"), hsl3.Value.ToString("N2"), "#4 Value (" + sample.Name + ")");
            }
        }
예제 #2
0
        public void RgbTo()
        {
            RgbColor rgb = new RgbColor(0, 0, 0, 0.5);

            Assert.AreEqual(0.5, rgb.ToCmy().Alpha, "To CMY");

            Assert.AreEqual(0.5, rgb.ToCmyk().Alpha, "To CMYK");

            Assert.AreEqual(0.5, rgb.ToHsl().Alpha, "To HSL");

            Assert.AreEqual(0.5, rgb.ToHsv().Alpha, "To HSV");

            Assert.AreEqual(0.5, rgb.ToRgb().Alpha, "To RGB");
        }
        private void SetPropertyValueFromRgb(int red, int green, int blue)
        {
            UI.SuspendControlPainting(this);

            try
            {
                if (this.redNud.Value != red)
                {
                    this.redNud.Value = red;
                }

                if (this.greenNud.Value != green)
                {
                    this.greenNud.Value = green;
                }

                if (this.blueNud.Value != blue)
                {
                    this.blueNud.Value = blue;
                }

                if (this.inOnPropertyValueChanged == 0)
                {
                    int newValue = (red << 16) | (green << 8) | blue;
                    if (Property.Value != newValue)
                    {
                        Property.Value = newValue;
                    }
                }

                RgbColor rgb = new RgbColor(red, green, blue);
                HsvColor hsv = rgb.ToHsv();
                this.hsvColorWheel.HsvColor = hsv;
                this.valueSlider.Value      = (hsv.Value * 255) / 100;
                this.saturationSlider.Value = (hsv.Saturation * 255) / 100;

                HsvColor hsvValMin = hsv;
                hsvValMin.Value = 0;
                HsvColor hsvValMax = hsv;
                hsvValMax.Value           = 100;
                this.valueSlider.MinColor = hsvValMin.ToColor();
                this.valueSlider.MaxColor = hsvValMax.ToColor();

                HsvColor hsvSatMin = hsv;
                hsvSatMin.Saturation = 0;
                HsvColor hsvSatMax = hsv;
                hsvSatMax.Saturation           = 100;
                this.saturationSlider.MinColor = hsvSatMin.ToColor();
                this.saturationSlider.MaxColor = hsvSatMax.ToColor();
            }

            finally
            {
                UI.ResumeControlPainting(this);

                if (UI.IsControlPaintingEnabled(this))
                {
                    Refresh();
                }
            }
        }
예제 #4
0
 void update(ColorModel source)
 {
     changingValues = true;
     GetBaseColor(source);
     if (source != ColorModel.Rgb)
     {
         RgbR = basecolor.R;
         RgbG = basecolor.G;
         RgbB = basecolor.B;
     }
     if (source != ColorModel.RgbPerc)
     {
         try
         {
             var c = basecolor.ToRgb(RgbType.Percent);
             RgbPercR = c.R;
             RgbPercG = c.G;
             RgbPercB = c.B;
         }
         catch (Exception ex)
         {
             Debug.WriteLine(ex);
             throw;
         }
     }
     if (source != ColorModel.RgbByte)
     {
         var c = basecolor.ToRgb(RgbType.Byte);
         RgbByteR = c.R;
         RgbByteG = c.G;
         RgbByteB = c.B;
     }
     if (source != ColorModel.Cmy)
     {
         var c = basecolor.ToCmyk();
         CmyC = c.C;
         CmyM = c.M;
         CmyY = c.Y;
     }
     if (source != ColorModel.Cmyk)
     {
         var c = basecolor.ToCmyk(CmykType.CmykNormalized);
         CmykC = c.C;
         CmykM = c.M;
         CmykY = c.Y;
         CmykK = c.K;
     }
     if (source != ColorModel.Hsv)
     {
         try
         {
             var c = basecolor.ToHsv();
             HsvH = c.H;
             HsvS = c.S;
             HsvV = c.V;
         }
         catch (Exception ex)
         {
             Debug.WriteLine(ex);
         }
     }
     if (source != ColorModel.Xyz)
     {
         var c = basecolor.ToXyz();
         XyzX = c.X;
         XyzY = c.Y;
         XyzZ = c.Z;
     }
     if (source != ColorModel.Yiq)
     {
         var c = basecolor.ToYiq();
         YiqY = c.Y;
         YiqI = c.I;
         YiqQ = c.Q;
     }
     if (source != ColorModel.hex)
     {
         var c = basecolor;
         Hex = c.Hex;
     }
     OnPropertyChanged("RectColor");
     changingValues = false;
 }