• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# RGB类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中RGB的典型用法代码示例。如果您正苦于以下问题:C# RGB类的具体用法?C# RGB怎么用?C# RGB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RGB类属于命名空间,在下文中一共展示了RGB类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: isCompatible

 /*
  * Check whether the color of the object this script is attached to is
  * compatible with the passed in color. Compatible colors are those that
  * either match or match one of the component colors in the color wheel.
  */
 public bool isCompatible(RGB theirRGB)
 {
     if (theirRGB.color == color) {
         return true;
     }
     return false;
 }
开发者ID:ilias1111,项目名称:game-off-2013,代码行数:12,代码来源:RGB.cs


示例2: GetContrast

 public static Color GetContrast(this Color Source, bool PreserveOpacity)
 {
     var inputColor = Source;
       //if RGB values are close to each other by a diff less than 10%, then if RGB values are lighter side, decrease the blue by 50% (eventually it will increase in conversion below), if RBB values are on darker side, decrease yellow by about 50% (it will increase in conversion)
       var avgColorValue = (byte) ((Source.R + Source.G + Source.B)/3);
       var diff_r = Math.Abs(Source.R - avgColorValue);
       var diff_g = Math.Abs(Source.G - avgColorValue);
       var diff_b = Math.Abs(Source.B - avgColorValue);
       if (diff_r < 20 && diff_g < 20 && diff_b < 20) //The color is a shade of gray
       {
     if (avgColorValue < 123) //color is dark
     {
       inputColor = Color.FromArgb(Source.A, 220, 230, 50);
     }
     else
     {
       inputColor = Color.FromArgb(Source.A, 255, 255, 50);
     }
       }
       var sourceAlphaValue = Source.A;
       if (!PreserveOpacity)
       {
     sourceAlphaValue = Math.Max(Source.A, (byte) 127); //We don't want contrast color to be more than 50% transparent ever.
       }
       var rgb = new RGB {R = inputColor.R, G = inputColor.G, B = inputColor.B};
       var hsb = ConvertToHSB(rgb);
       hsb.H = hsb.H < 180 ? hsb.H + 180 : hsb.H - 180;
       //_hsb.B = _isColorDark ? 240 : 50; //Added to create dark on light, and light on dark
       rgb = ConvertToRGB(hsb);
       return Color.FromArgb(sourceAlphaValue, (int) rgb.R, (int) rgb.G, (int) rgb.B);
 }
开发者ID:taradinoc,项目名称:trizbort,代码行数:31,代码来源:ColorExtensions.cs


示例3: HSVtoColor

        public static Color HSVtoColor(HSV hsv)
        {
            if (hsv == null)
                return Color.Blue;

            DRColor.RGB RGB = new RGB(hsv);
            return Color.FromArgb(RGB.Red, RGB.Green, RGB.Blue);
        }
开发者ID:RGKaizen,项目名称:DoubleRainbow,代码行数:8,代码来源:DRColor.cs


示例4: GetRGB

 public static RGB GetRGB(this Color self)
 {
     RGB rgb = new RGB();
     rgb.r = self.r;
     rgb.g = self.g;
     rgb.b = self.b;
     return rgb;
 }
开发者ID:DrSkipper,项目名称:ForAshley,代码行数:8,代码来源:ColorExtensions.cs


示例5: GetBufferFrames

        public void GetBufferFrames()
        {
            FileBuffer.Seek(0, SeekOrigin.Begin);
            BinaryFormatter mFormatter = new BinaryFormatter(FileBuffer);
            FlcHeader.ReadData(mFormatter);
            Civ3Header.ReadData(mFormatter);

            SFliFrameHeader frameHeader = new SFliFrameHeader();
            SFliChunkHeader chunkHeader = new SFliChunkHeader();

            mBufferFrames = new byte[FlcHeader.frames + 8][];
            mColourMap = new RGB[FlcHeader.frames + 8][];

            for (short frame = 0; frame < FlcHeader.frames + 8; frame++) {

                mBufferFrames[frame] = new byte[FlcHeader.width * FlcHeader.height];
                mColourMap[frame] = new RGB[256];

                if (frame > 0) {
                    Array.Copy(mBufferFrames[frame - 1], mBufferFrames[frame], sizeof(byte) * (FlcHeader.width * FlcHeader.height));
                    Array.Copy(mColourMap[frame - 1], mColourMap[frame], 256);
                }

                frameHeader.ReadData(mFormatter);

                if (frameHeader.magic != 0xf1fa) {
                    //fseek(fp, frameHeader.Size - sizeof(frameHeader), SEEK_CUR);

                    ulong size = (ulong)System.Runtime.InteropServices.Marshal.SizeOf(typeof(SFliFrameHeader));
                    mFormatter.ReadBytes((int)(frameHeader.size - size));

                    FlcHeader.frames--;
                    frame--;
                    continue;
                }

                for (int chunk = 0; chunk < frameHeader.chunks; chunk++) {
                    chunkHeader.ReadData(mFormatter);

                    switch (chunkHeader.type) {
                        case 4:
                            FlcColour256(mFormatter, frame);
                            break;
                        case 7:
                            long read = FlcDeltaFlc(mFormatter, frame);
                            mFormatter.ReadBytes((int)((long)chunkHeader.size - read));
                            break;
                        case 15:
                            FlcBitwiseRun(mFormatter, frame);
                            break;
                        default:
                            throw new NotImplementedException();

                    }
                }

            }
        }
开发者ID:jimmyh77,项目名称:IndieCiv,代码行数:58,代码来源:Flc.cs


示例6: asRGB

        /// <summary>
        /// transformation HSV -> RGB
        /// source: http://en.wikipedia.org/wiki/HSL_and_HSV (consistent with anything found on the web)
        /// </summary>
        /// <author>Birthe Anne Wiegand</author>
        /// <returns>the RGB value</returns>
        public RGB asRGB()
        {
            RGB temp = new RGB();

            float f = this.H / 60f - (float)Math.Floor(this.H / 60f);
            float p = this.V * (1f - this.S);
            float q = this.V * (1f - this.S * f);
            float t = this.V * (1f - this.S * (1 - f));

            if (0f <= this.H && this.H < 60f)
            {
                temp.R = this.V;
                temp.G = t;
                temp.B = p;
            }
            else if (60f <= this.H && this.H < 120f)
            {
                temp.R = q;
                temp.G = this.V;
                temp.B = p;
            }
            else if (120f <= this.H && this.H < 180f)
            {
                temp.R = p;
                temp.G = this.V;
                temp.B = t;
            }
            else if (180f <= this.H && this.H < 240f)
            {
                temp.R = p;
                temp.G = q;
                temp.B = this.V;
            }
            else if (240f <= this.H && this.H < 300f)
            {
                temp.R = t;
                temp.G = p;
                temp.B = this.V;
            }
            else if (300f <= this.H && this.H < 360f)
            {
                temp.R = this.V;
                temp.G = p;
                temp.B = q;
            }
            else
            {
                System.Diagnostics.Debug.Write("HSV to RGB out of range");
            }

            return temp;
        }
开发者ID:ArTc0re,项目名称:University,代码行数:58,代码来源:HSV.cs


示例7: setPalette

        public void setPalette(int colorCount, bool save = false)
        {
            unsafe
            {
                Clear();

                for (int y = 0; y < Buffer.heightInPixels; y++)
                {
                    byte* currentLine = Buffer.ptrFirstPixel + (y * Buffer.stride);
                    for (int x = 0; x < Buffer.widthInBytes; x = x + Buffer.bytesPerPixel)
                    {
                        colorList.Add(new RGB(Buffer.memoryStream[y, x + 2], Buffer.memoryStream[y, x + 1], Buffer.memoryStream[y, x]));
                    }
                }

                List<RGB> palette = GetPalette(colorCount);
                int k = 0;
                for (int y = 0; y < Buffer.heightInPixels; y++)
                {
                    byte* currentLine = Buffer.ptrFirstPixel + (y * Buffer.stride);
                    for (int x = 0; x < Buffer.widthInBytes; x = x + Buffer.bytesPerPixel)
                    {

                        RGB color = new RGB(Buffer.memoryStream[y,x + 2], Buffer.memoryStream[y,x + 1], Buffer.memoryStream[y,x]);
                        
                        Int32 b;
                        if (!cache.TryGetValue(color, out b))
                        {
                            for (int i = 0; i < cubeList.Count; i++)
                            {
                                if (cubeList[i].IsColorIn(color))
                                {
                                    b = cubeList[i].PaletteIndex;
                                    break;
                                }
                            }
                        }

                        currentLine[x + 2] = palette[b].R;
                        currentLine[x + 1] = palette[b].G;
                        currentLine[x] = palette[b].B;
                    }
                }
                if (save)
                    Buffer.addData();
                Buffer.Refrash();

            }
        }
开发者ID:sapun4ik,项目名称:Pixer,代码行数:49,代码来源:Palette.cs


示例8: UnionTest

        public void UnionTest()
        {
            // Byte is a value type, and will default to 0,
            // so the default colour will be black!
            var black = new RGB();
            Assert.AreEqual(black.AsHex(), "000000");

            var coral = new RGB(255, 125, 125);
            Assert.AreEqual(coral.AsHex(), "FF7D7D");

            var coralConverted = new RGB().FromHex("FF7D7D");
            Assert.AreEqual(coralConverted.R, 255);
            Assert.AreEqual(coralConverted.G, 125);
            Assert.AreEqual(coralConverted.B, 125);
        }
开发者ID:WhatIsHeDoing,项目名称:DidYouKnow,代码行数:15,代码来源:Union.cs


示例9: DoSwirlies

        Pixel DoSwirlies(int x, int y)
        {
            var rgb = new RGB(0.0, 0.0, 0.0);

              const double zoom = 0.5;
              const int terms = 5;

              _swirlies.ForEach(swirly =>
            swirly.CalculateOnePoint(terms, _width, _height, zoom,
                         x, y, rgb));

              return new Pixel(FloatToIntPixel(RemapColorRange(rgb.R)),
               FloatToIntPixel(RemapColorRange(rgb.G)),
               FloatToIntPixel(RemapColorRange(rgb.B)));
        }
开发者ID:unhammer,项目名称:gimp-sharp,代码行数:15,代码来源:Renderer.cs


示例10: CombineColorChannels

        public static byte[] CombineColorChannels(RGB[] rgb)
        {
            byte[] data = new byte[rgb.Length * 3];

            int counter = 0;
            for (int i = 0; i < data.Length; i += 3)
            {
                data[i] = rgb[counter].r;
                data[i + 1] = rgb[counter].g;
                data[i + 2] = rgb[counter].b;

                ++counter;
            }

            return data;
        }
开发者ID:opentibia,项目名称:item-editor,代码行数:16,代码来源:ImageUtils.cs


示例11: Load

        protected override Image Load()
        {
            if (ReadHeader())
            {
              var colormap = new RGB[] {
            new RGB(255,255,255),
            new RGB(255,0,0),
            new RGB(0,255,0),
            new RGB(255,255,0),
            new RGB(0,0,255),
            new RGB(255,0,255),
            new RGB(0,255,255),
            new RGB(181,181,181),
            new RGB(84,84,84),
            new RGB(127,0,0),
            new RGB(0,127,0),
            new RGB(127,127,0),
            new RGB(0,0,127),
            new RGB(127,0,127),
            new RGB(0,127,127),
            new RGB(0,0,0)
              };

              var image = NewImage(_imageWidth, _imageHeight,
                   ImageBaseType.Indexed,
                   ImageType.Indexed, Filename);
              image.Colormap = colormap;
              var rgn = new PixelRgn(image.Layers[0], true, false);

              int bparrow = (_imageWidth + 7) / 8;

              for (int y = 0; y < _imageHeight; )
            {
              // byte[] line = new byte[bparrow * 8];
              var line = new byte[_imageWidth];
              int count = ReadLine(line);
              do
            {
              rgn.SetRow(line, 0, y++);
            }
              while (--count > 0);
            }

              return image;
            }
              return null;
        }
开发者ID:unhammer,项目名称:gimp-sharp,代码行数:47,代码来源:GemImg.cs


示例12: FxImages_32bppArgb

        public FxImages_32bppArgb(Bitmap Image)
        {
            if (Image.PixelFormat != PixelFormat.Format32bppArgb)
            {
                throw new ArgumentException("The input image must 32bppArgb");
            }

            // set the pilex format
            FXPixelFormat = new RGB[4];
            FXPixelFormat[0] = RGB.B;
            FXPixelFormat[1] = RGB.G;
            FXPixelFormat[2] = RGB.R;
            FXPixelFormat[3] = RGB.A;

            // set the internal image
            localImage = Image;
        }
开发者ID:fxbit,项目名称:FxMath,代码行数:17,代码来源:FxImages_32bppArgb.cs


示例13: ConvertToHSB

        internal static HSB ConvertToHSB(RGB rgb)
        {
            // Following code is taken as it is from MSDN. See link below.
              // By: <a href="http://blogs.msdn.com/b/codefx/archive/2012/02/09/create-a-color-picker-for-windows-phone.aspx" title="MSDN" target="_blank">Yi-Lun Luo</a>
              var r = rgb.R;
              var g = rgb.G;
              var b = rgb.B;

              var max = Max(r, g, b);
              var min = Min(r, g, b);
              var chroma = max - min;
              var hue2 = 0d;
              if (chroma != 0)
              {
            if (max == r)
            {
              hue2 = (g - b)/chroma;
            }
            else if (max == g)
            {
              hue2 = (b - r)/chroma + 2;
            }
            else
            {
              hue2 = (r - g)/chroma + 4;
            }
              }
              var hue = hue2*60;
              if (hue < 0)
              {
            hue += 360;
              }
              var brightness = max;
              double saturation = 0;
              if (chroma != 0)
              {
            saturation = chroma/brightness;
              }
              return new HSB
              {
            H = hue,
            S = saturation,
            B = brightness
              };
        }
开发者ID:taradinoc,项目名称:trizbort,代码行数:45,代码来源:ColorExtensions.cs


示例14: Bilinear

        /// <summary>
        /// interpolate the input image in the specific position 
        /// and specific color, return byte
        /// </summary>
        /// <param name="image"></param>
        /// <param name="xf"></param>
        /// <param name="yf"></param>
        /// <param name="color"></param>
        /// <returns></returns>
        public static byte Bilinear(FxImages image, float xf, float yf, RGB color)
        {
            if (yf + 1>= image.Image.Height)
                yf = image.Image.Height - 2;

            if (xf + 1 >= image.Image.Width)
                xf = image.Image.Width - 2;

            // get the integer part of the position
            int x = (int)Math.Floor(xf);
            int y = (int)Math.Floor(yf);

            // get the ratio part
            double x_ratio = xf - x;
            double y_ratio = yf - y;

            // the inverse ratio
            double x_opposite = 1 - x_ratio;
            double y_opposite = 1 - y_ratio;

            byte result = 0;

            // interpolate on x
            if (y_opposite > 0)
            {
                if (x_opposite > 0)
                    result += (byte)(image[x, y, color] * x_opposite * y_opposite);

                if (x_ratio > 0)
                    result += (byte)(image[x + 1, y, color] * x_ratio * y_opposite);
            }

            // interpolate on y
            if (y_ratio > 0)
            {
                if (x_opposite > 0)
                    result += (byte)(image[x, y + 1, color] * x_opposite * y_ratio);

                if (x_ratio > 0)
                    result += (byte)(image[x + 1, y + 1, color] * x_ratio * y_ratio);
            }
            return result;
        }
开发者ID:fxbit,项目名称:FxMath,代码行数:52,代码来源:FxTools.cs


示例15: GetMaterialForRGB

 /*
  * Gets the material that is associated with the specified RGB's color
  */
 public static Material GetMaterialForRGB( RGB rgb)
 {
     Material returnMaterial = null;
     switch (rgb.color) {
     case ColorWheel.red:
         returnMaterial = ColorManager.Instance.red;
         break;
     case ColorWheel.green:
         returnMaterial = ColorManager.Instance.green;
         break;
     case ColorWheel.blue:
         returnMaterial = ColorManager.Instance.blue;
         break;
     case ColorWheel.black:
         returnMaterial = ColorManager.Instance.black;
         break;
     }
     return returnMaterial;
 }
开发者ID:ilias1111,项目名称:game-off-2013,代码行数:22,代码来源:RGB.cs


示例16: FxImages_8bpp

        public FxImages_8bpp(Bitmap Image)
        {
            if (Image.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                throw new ArgumentException("The input image must be 8 Bit per pixel");
            }

            // set the pilex format
            FXPixelFormat = new RGB[1];
            FXPixelFormat[0] = RGB.B;

            // set the internal image
            localImage = Image;

            /// make the grayscale palette
            ColorPalette greyPal = Image.Palette;
            for (int i = 0; i < greyPal.Entries.Length; i++)
                greyPal.Entries[i] = Color.FromArgb(i, i, i);
            Image.Palette = greyPal;
        }
开发者ID:fxbit,项目名称:FxMath,代码行数:20,代码来源:FxImages_8bpp.cs


示例17: Form1

        public Form1()
        {
            InitializeComponent();

            this.numericUpDown1.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.bindingSource1, "R", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
            this.numericUpDown2.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.bindingSource1, "G", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
            this.numericUpDown3.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.bindingSource1, "B", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            this.trackBar1.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.bindingSource1, "R", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
            this.trackBar2.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.bindingSource1, "G", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
            this.trackBar3.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.bindingSource1, "B", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

            RGB rgb1 = new RGB();
            rgb1.R = 100;
            rgb1.G = 200;
            rgb1.B = 50;
            this.bindingSource1.DataSource = rgb1;

            ((RGB)(this.bindingSource1.DataSource)).R = 5;
            ((RGB)(this.bindingSource1.DataSource)).G = 205;
            ((RGB)(this.bindingSource1.DataSource)).B = 55;
        }
开发者ID:ytyaru,项目名称:BindingSource20160619,代码行数:22,代码来源:Form1.cs


示例18: LinkComponents

 /*
  * Sets references to components on this Player game object or one of its children
  */
 void LinkComponents()
 {
     bluePower = (BluePower)GetComponent<BluePower> ();
     redPower = (RedPower)GetComponent<RedPower> ();
     greenPower = (GreenPower)GetComponent<GreenPower> ();
     playerRGB = (RGB)playerGeo.GetComponent<RGB> ();
     inventory = (Inventory)GetComponent<Inventory> ();
 }
开发者ID:ilias1111,项目名称:game-off-2013,代码行数:11,代码来源:Player.cs


示例19: GetPowerForColor

 /*
  * Map our player's power bars to the color passed in by returning
  * the power associated with the provided color.
  */
 Power GetPowerForColor(RGB rgb)
 {
     ColorWheel color = rgb.color;
     Power returnPower = null;
     switch (color) {
     case ColorWheel.blue:
         returnPower = bluePower;
         break;
     case ColorWheel.red:
         returnPower = redPower;
         break;
     case ColorWheel.green:
         returnPower = greenPower;
         break;
     }
     return returnPower;
 }
开发者ID:ilias1111,项目名称:game-off-2013,代码行数:21,代码来源:Player.cs


示例20: ProcessFilter

        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="image">Source image data.</param>
        /// <param name="rect">Image rectangle for processing by the filter.</param>
        ///
        protected override unsafe void ProcessFilter( UnmanagedImage image, Rectangle rect )
        {
            // get pixel size
            int pixelSize = ( image.PixelFormat == PixelFormat.Format24bppRgb ) ? 3 : 4;

            int startX  = rect.Left;
            int startY  = rect.Top;
            int stopX   = startX + rect.Width;
            int stopY   = startY + rect.Height;
            int offset  = image.Stride - rect.Width * pixelSize;

            RGB rgb = new RGB( );
            YCbCr ycbcr = new YCbCr( );

            bool updated;

            // do the job
            byte* ptr = (byte*) image.ImageData.ToPointer( );

            // allign pointer to the first pixel to process
            ptr += ( startY * image.Stride + startX * pixelSize );

            // for each row
            for ( int y = startY; y < stopY; y++ )
            {
                // for each pixel
                for ( int x = startX; x < stopX; x++, ptr += pixelSize )
                {
                    updated   = false;
                    rgb.Red   = ptr[RGB.R];
                    rgb.Green = ptr[RGB.G];
                    rgb.Blue  = ptr[RGB.B];

                    // convert to YCbCr
                    AForge.Imaging.YCbCr.FromRGB( rgb, ycbcr );

                    // check YCbCr values
                    if (
                        ( ycbcr.Y >= yRange.Min )   && ( ycbcr.Y <= yRange.Max ) &&
                        ( ycbcr.Cb >= cbRange.Min ) && ( ycbcr.Cb <= cbRange.Max ) &&
                        ( ycbcr.Cr >= crRange.Min ) && ( ycbcr.Cr <= crRange.Max )
                        )
                    {
                        if ( !fillOutsideRange )
                        {
                            if ( updateY ) ycbcr.Y   = fillY;
                            if ( updateCb ) ycbcr.Cb = fillCb;
                            if ( updateCr ) ycbcr.Cr = fillCr;

                            updated = true;
                        }
                    }
                    else
                    {
                        if ( fillOutsideRange )
                        {
                            if ( updateY ) ycbcr.Y   = fillY;
                            if ( updateCb ) ycbcr.Cb = fillCb;
                            if ( updateCr ) ycbcr.Cr = fillCr;

                            updated = true;
                        }
                    }

                    if ( updated )
                    {
                        // convert back to RGB
                        AForge.Imaging.YCbCr.ToRGB( ycbcr, rgb );

                        ptr[RGB.R] = rgb.Red;
                        ptr[RGB.G] = rgb.Green;
                        ptr[RGB.B] = rgb.Blue;
                    }
                }
                ptr += offset;
            }
        }
开发者ID:RevDevBev,项目名称:aforge.net,代码行数:84,代码来源:YCbCrFiltering.cs



注:本文中的RGB类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# RGBA_Bytes类代码示例发布时间:2022-05-24
下一篇:
C# RESTCommand类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap