【问题标题】:Color.HSBtoRGB missing in WinRTWinRT 中缺少 Color.HSBtoRGB
【发布时间】:2012-10-20 07:30:07
【问题描述】:

我正在构建一个分形应用程序,需要生成一个平滑的配色方案,我在 Smooth spectrum for Mandelbrot Set rendering 找到了一个不错的算法。

但这需要我调用 Color.HSBtoRGB,并且该方法在 WinRT / Windows 应用商店应用程序中不可用。

还有其他内置方法可以进行这种转换吗? 关于如何将 HSB 转换为 RGB 的其他提示?

【问题讨论】:

    标签: colors windows-runtime fractals windows-store-apps


    【解决方案1】:

    我最终使用了http://www.adafruit.com/blog/2012/03/14/constant-brightness-hsb-to-rgb-algorithm/ 上的 HSB 到 RGB 转换算法,我采用了初始(长)版本。也许这可以进一步优化,但对我来说这是完美的!

    由于 hsb2rgb 方法在 C 中并且我需要 C#,所以我在这里分享我的版本:

        private byte[] hsb2rgb(int index, byte sat, byte bright)
        {
            int r_temp, g_temp, b_temp;
            byte index_mod;
            byte inverse_sat = (byte)(sat ^ 255);
    
            index = index % 768;
            index_mod = (byte)(index % 256);
    
            if (index < 256)
            {
                r_temp = index_mod ^ 255;
                g_temp = index_mod;
                b_temp = 0;
            }
            else if (index < 512)
            {
                r_temp = 0;
                g_temp = index_mod ^ 255;
                b_temp = index_mod;
            }
    
            else if ( index < 768)
            {
                r_temp = index_mod;
                g_temp = 0;
                b_temp = index_mod ^ 255;
            }
    
            else
            {
                r_temp = 0;
                g_temp = 0;
                b_temp = 0;
            }
    
            r_temp = ((r_temp * sat) / 255) + inverse_sat;
            g_temp = ((g_temp * sat) / 255) + inverse_sat;
            b_temp = ((b_temp * sat) / 255) + inverse_sat;
    
            r_temp = (r_temp * bright) / 255;
            g_temp = (g_temp * bright) / 255;
            b_temp = (b_temp * bright) / 255;
    
            byte[] color = new byte[3];
            color[0]    = (byte)r_temp;
            color[1]    = (byte)g_temp;
            color[2]    = (byte)b_temp;
    
            return color;
        }
    

    要根据原始帖子中链接的代码调用它,我需要进行一些小的修改:

        private byte[] SmoothColors1(int maxIterationCount, ref Complex z, int iteration)
        {
            double smoothcolor = iteration + 1 - Math.Log(Math.Log(z.Magnitude)) / Math.Log(2);
            byte[] color = hsb2rgb((int)(10 * smoothcolor), (byte)(255 * 0.6f), (byte)(255 * 1.0f));
    
            if (iteration >= maxIterationCount)
            {
                // Make sure the core is black
                color[0] = 0;
                color[1] = 0;
                color[2] = 0;
            }
            return color;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-23
      • 2011-12-11
      • 2011-05-29
      • 2012-06-12
      相关资源
      最近更新 更多