示例#1
0
        public void ToCmy()
        {
            foreach (HtmlColorSample sample in HtmlColorSamples.All)
            {
                double h = sample.Hsv.Hue / 360d;
                double s = sample.Hsv.Saturation;
                double v = sample.Hsv.Value;

                HsvColor hsv = new HsvColor(h, s, v);

                double c1 = sample.Cmy.Cyan;
                double m1 = sample.Cmy.Magenta;
                double y1 = sample.Cmy.Yellow;

                ColorUtils.HsvToCmy(h, s, v, out double c2, out double m2, out double y2);
                Assert.AreEqual(c1.ToString("N2"), c2.ToString("N2"), "#1 C (" + sample.Name + ")");
                Assert.AreEqual(m1.ToString("N2"), m2.ToString("N2"), "#1 M (" + sample.Name + ")");
                Assert.AreEqual(y1.ToString("N2"), y2.ToString("N2"), "#1 Y (" + sample.Name + ")");

                CmyColor cmy1 = ColorUtils.HsvToCmy(h, s, v);
                Assert.AreEqual(c1.ToString("N2"), cmy1.C.ToString("N2"), "#2 C (" + sample.Name + ")");
                Assert.AreEqual(m1.ToString("N2"), cmy1.M.ToString("N2"), "#2 M (" + sample.Name + ")");
                Assert.AreEqual(y1.ToString("N2"), cmy1.Y.ToString("N2"), "#2 Y (" + sample.Name + ")");

                CmyColor cmy2 = ColorUtils.HsvToCmy(hsv);
                Assert.AreEqual(c1.ToString("N2"), cmy2.C.ToString("N2"), "#3 C (" + sample.Name + ")");
                Assert.AreEqual(m1.ToString("N2"), cmy2.M.ToString("N2"), "#3 M (" + sample.Name + ")");
                Assert.AreEqual(y1.ToString("N2"), cmy2.Y.ToString("N2"), "#3 Y (" + sample.Name + ")");

                CmyColor cmy3 = hsv.ToCmy();
                Assert.AreEqual(c1.ToString("N2"), cmy3.C.ToString("N2"), "#4 C (" + sample.Name + ")");
                Assert.AreEqual(m1.ToString("N2"), cmy3.M.ToString("N2"), "#4 M (" + sample.Name + ")");
                Assert.AreEqual(y1.ToString("N2"), cmy3.Y.ToString("N2"), "#4 Y (" + sample.Name + ")");
            }
        }
示例#2
0
        public void HsvTo()
        {
            HsvColor hsv = new HsvColor(208, 0.05882352941176472, 1, 0.5);

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

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

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

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

            Assert.AreEqual(0.5, hsv.ToRgb().Alpha, "To RGB");
        }