当前位置: 首页>>代码示例>>C#>>正文


C# Color.Contains方法代码示例

本文整理汇总了C#中Color.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Color.Contains方法的具体用法?C# Color.Contains怎么用?C# Color.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Color的用法示例。


在下文中一共展示了Color.Contains方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Combine

        public static Color Combine(this Color color, Color otherColor)
        {
            // primary combinations
            if ((color == Red && otherColor == Blue) || (color == Blue && otherColor == Red))
                return Purple;
            if ((color == Blue && otherColor == Yellow) || (color == Yellow && otherColor == Blue))
                return Green;
            if ((color == Red && otherColor == Yellow) || (color == Yellow && otherColor == Red))
                return Orange;

            // redundant color combinations
            if (color.Contains(otherColor))
                return color;
            if (otherColor.Contains(color))
                return otherColor;

            #if DEBUG
            Console.WriteLine(String.Format("Possibly unsupported color combination: {0} and {1}", color.ToString(), otherColor.ToString()));
            #endif
            return Black;
        }
开发者ID:akbiggs,项目名称:Trauma,代码行数:21,代码来源:ColorHelper.cs

示例2: Generate

        public void Generate()
        {
            // Highly experimental
            // Componer paleta
            Color[] tpalette = new Color[paleta_extra.Length];//[256];
            int i = 0;
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Color color = bitmap.GetPixel(x, y);
                    if (!tpalette.Contains(color))
                    {
                        tpalette.SetValue(color, i);
                        i++;
                    }
                }
            }
            // Pasar la paleta a 555Color
            palette = new _555Color[tpalette.Length];
            for (int j = 0; j < tpalette.Length; j++)
            {
                //palette.SetValue(new _555Color(tpalette[j]), j);
                palette.SetValue(paleta_extra[j], j);
            }

            // Generar los tiles numericos
            int total = width * height;
            total_tiles = (ushort)(total / 64);
            int current = 0;
            int extra_x = 0;
            int extra_y = 0;
            // array con todos los bytes de los tiles
            tiles = new byte[width * height];
            while (current < total)
            {
                for (int y = 0; y < 8; y++)
                {
                    for (int x = 0; x < 8; x++)
                    {
                        Color color = bitmap.GetPixel(x + extra_x, y + extra_y);
                        _555Color color2 = new _555Color(color);
                        for (int j = 0; j < palette.Length; j++)
                        {
                            if (palette[j].Int16 == color2.Int16)
                            {
                                // Guardar la posicion del color
                                tiles.SetValue((byte)j, current);
                                break;
                            }
                            else { tiles.SetValue((byte)0, current); }
                        }
                        current++;
                    }
                }
                extra_x += 8;
                if (extra_x >= width)
                {
                    extra_x = 0;
                    extra_y += 8;
                }
            }
        }
开发者ID:Dahrkael,项目名称:RMDSCM,代码行数:63,代码来源:CHBGWriter.cs

示例3: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                bmp = (Bitmap)Bitmap.FromFile(openFileDialog1.FileName);

                pictureBox1.Height = bmp.Height;
                pictureBox1.Width = bmp.Width;
                pictureBox1.Image = bmp;

                if (pictureBox1.Height > 240)
                {
                    this.Height = pictureBox1.Top + pictureBox1.Height + 60;
                }
                this.Width = pictureBox1.Left + pictureBox1.Width + 40;

                for (int row = 0; row < bmp.Height; row++)
                {
                    int coloursThisRow = 0;
                    Color[] rowColors = new Color[0];

                    for (int stitch = 0; stitch < bmp.Width; stitch++)
                    {

                        thisStitch = bmp.GetPixel(stitch, row);

                        if (!colors.Contains(thisStitch))
                        {
                            Array.Resize(ref colors, colors.Length + 1);
                            colors[colors.Length - 1] = thisStitch;
                        }

                        if (!rowColors.Contains(thisStitch))
                        {
                            Array.Resize(ref rowColors, rowColors.Length + 1);
                            rowColors[rowColors.Length - 1] = thisStitch;
                            coloursThisRow++;
                        }

                        if (coloursThisRow > MaxColoursPerRow)
                        {
                            MaxColoursPerRow = coloursThisRow;
                        }
                    }

                }

                for (int i = 0; i < colors.Length; i++)
                {
                    Array.Resize(ref colorButtons, colorButtons.Length + 1);
                    colorButtons[colorButtons.Length - 1] = new Button();
                    colorButtons[colorButtons.Length - 1].Left = 10;
                    colorButtons[colorButtons.Length - 1].Top = i * (colorButtons[colorButtons.Length - 1].Height + 3) + 60;
                    colorButtons[colorButtons.Length - 1].BackColor = colors[i];
                    this.Controls.Add(colorButtons[colorButtons.Length - 1]);

                    Array.Resize(ref colorNumber, colorNumber.Length + 1);
                    colorNumber[colorNumber.Length - 1] = new TextBox();
                    colorNumber[colorNumber.Length - 1].Left = colorButtons[colorButtons.Length - 1].Left + colorButtons[colorButtons.Length - 1].Width + 10;
                    colorNumber[colorNumber.Length - 1].Top = colorButtons[colorButtons.Length - 1].Top;
                    colorNumber[colorNumber.Length - 1].Text = (i + 1).ToString();

                    this.Controls.Add(colorNumber[colorNumber.Length - 1]);
                }

                label1.Text = "Max colours per row: " + MaxColoursPerRow.ToString();
                label2.Text = "Rows: " + bmp.Height.ToString();
                label3.Text = "Stitches: " + bmp.Width.ToString();

                // button1.Text = colors.Length.ToString();

                if (MaxColoursPerRow > 2)
                {
                    buttonConvert.Visible = true;
                    button1.Visible = false;
                }
                else
                {
                    buttonConvert.Visible = false;
                    button1.Visible = true;
                }
            }
        }
开发者ID:kentfield,项目名称:multicolourjacquard,代码行数:83,代码来源:Form1.cs

示例4: button2_Click

        private void button2_Click(object sender, EventArgs e)
        {
            int colour;
            int i;

            output = new Byte[bmp.Height, bmp.Width];

            for (int row = 0; row < bmp.Height; row++)
            {
                Color[] rowColors = new Color[MaxColoursPerRow];
                int colorCount = 0;

                for (int stitch = 0; stitch < bmp.Width; stitch++)
                {
                    thisStitch = bmp.GetPixel(stitch, row);

                    if (!rowColors.Contains(thisStitch))
                    {
                        rowColors[colorCount++] = thisStitch;
                    }
                }

                for (int stitch = 0; stitch < bmp.Width; stitch++)
                {
                    thisStitch = bmp.GetPixel(stitch, row);

                    for (i = 0; i < colors.Length; i++)
                    {
                        if (thisStitch == colors[i])
                        {
                            colour = Convert.ToInt32(colorNumber[i].Text);
                            output[row, stitch] = (Byte)colour;
                            break;
                        }
                    }
                }
            }

            // Array 'output' now contains one byte per pixel (stitch), with number representing colour of yarn to use. Let's dump it to a file for reference.

            System.IO.StreamWriter stream = new System.IO.StreamWriter("C:\\Knitulator\\Frontproof.txt");

            for (int row = 0; row < bmp.Height; row++)
            {
                for (int stitch = 0; stitch < bmp.Width; stitch++)
                {
                    stream.Write(output[row, stitch].ToString());
                }
                stream.WriteLine();
            }

            stream.Close();

            // Now lets create a Multicolour pattern, where each row contains a boolean indicating do or don't use the colour.
            // A separate array is required, for each row to indicate which colour to use.

            //TOD: Make sure patternRowColour is multiple of 2 as colours are stored as nibbles

            Byte[] patternRowColour = new Byte[bmp.Height * MaxColoursPerRow]; // Array to hold colour of yarn to use on each Multicolour row

            int widthInBits = (int)(8 * Math.Round(bmp.Width / (double)8, MidpointRounding.AwayFromZero));    // must be multiple of 8 bits

            Byte[,] pattern = new Byte[bmp.Height * MaxColoursPerRow, widthInBits]; // Array to hold pattern data = 1 byte represents 8 stitches

            System.IO.StreamWriter stream2 = new System.IO.StreamWriter("C:\\Knitulator\\Frontmc.txt");

            int n = bmp.Height * MaxColoursPerRow;

            stream2.WriteLine("Row : Disp : Col : Row Pattern");

            for (int row = 0; row < bmp.Height; row++)
            {
                // Work out which colours to knit:
                Byte[] rowColours = new Byte[MaxColoursPerRow];
                int colourCount = 0;

                for (int stitch = 0; stitch < bmp.Width; stitch++)
                {
                    if (!rowColours.Contains(output[row, stitch]))
                    {
                        rowColours[colourCount++] = output[row, stitch];
                    }
                }

                if (rowColours[1] == 0)
                {
                    rowColours[1] = 8;
                    rowColours[2] = 9;
                }

                if (rowColours[2] == 0)
                {
                    rowColours[2] = 9;
                }

                for (i = 0; i < MaxColoursPerRow; i++)
                {
                    stream2.Write((bmp.Height - row).ToString("D3") + " : ");
                    stream2.Write(n.ToString("D3") + "  : ");
                    n--;
//.........这里部分代码省略.........
开发者ID:kentfield,项目名称:multicolourjacquard,代码行数:101,代码来源:Form1.cs

示例5: button1_Click_1

        private void button1_Click_1(object sender, EventArgs e)
        {
            int colour;
            int i;

            output = new Byte[bmp.Height, bmp.Width];

            for (int row = 0; row < bmp.Height; row++)
            {
                Color[] rowColors = new Color[MaxColoursPerRow];
                int colorCount = 0;

                for (int stitch = 0; stitch < bmp.Width; stitch++)
                {
                    thisStitch = bmp.GetPixel(stitch, row);

                    if (!rowColors.Contains(thisStitch))
                    {
                        rowColors[colorCount++] = thisStitch;
                    }
                }

                for (int stitch = 0; stitch < bmp.Width; stitch++)
                {
                    thisStitch = bmp.GetPixel(stitch, row);

                    for (i = 0; i < colors.Length; i++)
                    {
                        if (thisStitch == colors[i])
                        {
                            colour = Convert.ToInt32(colorNumber[i].Text);
                            output[row, stitch] = (Byte)colour;
                            break;
                        }
                    }
                }
            }

            // Array 'output' now contains one byte per pixel (stitch), with number representing colour of yarn to use. Let's dump it to a file for reference.

            System.IO.StreamWriter stream = new System.IO.StreamWriter("C:\\Knitulator\\proof.txt");

            for (int row = 0; row < bmp.Height; row++)
            {
                for (int stitch = 0; stitch < bmp.Width; stitch++)
                {
                    stream.Write(output[row, stitch].ToString());
                }
                stream.WriteLine();
            }

            stream.Close();

            // Now lets create a 2 colour pattern, where each row contains a boolean indicating do or don't use the contrast yarn.

            int widthInBits = (int)(8 * Math.Round(bmp.Width / (double)8, MidpointRounding.AwayFromZero));    // must be multiple of 8 bits

            Byte[,] pattern = new Byte[bmp.Height, widthInBits]; // Array to hold pattern data = 1 byte represents 8 stitches

            System.IO.StreamWriter stream2 = new System.IO.StreamWriter("C:\\Knitulator\\2col.txt");

            int n = bmp.Height;

            stream2.WriteLine("Row : Row Pattern");

            for (int row = 0; row < bmp.Height; row++)
            {
                stream2.Write((bmp.Height - row).ToString("D3") + " : ");
                n--;

                for (int stitch = 0; stitch < bmp.Width; stitch++)
                {
                    if (output[row, stitch] == 2)
                    {
                        stream2.Write("X");
                        pattern[row, stitch] = 1;
                    }
                    else
                    {
                        stream2.Write(".");
                        pattern[row, stitch] = 0;
                    }
                }
                stream2.WriteLine();
            }

            stream2.Close();

            // Now create binary array in brother format, 1 bit per pixel
            Byte[,] patternOut = new Byte[bmp.Height, widthInBits / 8];

            for (int row = 0; row < bmp.Height; row++)
            {
                Byte bit = 0;
                for (int stitch = 0; stitch < widthInBits; stitch++)
                {
                    bit = (Byte)(stitch & 0x07);
                    bit = (Byte)(0x80 >> bit);

                    patternOut[row, stitch / 8] = (Byte)(patternOut[row, stitch / 8] | ((2 ^ bit) * pattern[row, stitch]));
//.........这里部分代码省略.........
开发者ID:kentfield,项目名称:multicolourjacquard,代码行数:101,代码来源:Form1.cs


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