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


C# Color.Select方法代码示例

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


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

示例1: DrawString

        /// <summary>
        /// Draws text with a border.
        /// </summary>
        /// <param name="gfx">The source graphics object</param>
        /// <param name="text">The text to render</param>
        /// <param name="font">The font to render</param>
        /// <param name="brush">The brush to use for the rendered text</param>
        /// <param name="x">The x location to render the text at</param>
        /// <param name="y">The y location to render the text at</param>
        /// <param name="border">The width of the border to render in pixels</param>
        /// <param name="borderColors">A collection of colors to border should cycle through</param>
        /// <param name="colorOffsets">An index-matching collection of offsets to render the border colors at</param>
        public static void DrawString(this Graphics gfx, string text, Font font, Brush brush, int x, int y, int border, Color[] borderColors, float[] colorOffsets)
        {
            if (string.IsNullOrWhiteSpace(text))
                return;
            if (gfx == null)
                throw new ArgumentNullException("gfx");
            if (font == null)
                throw new ArgumentNullException("font");
            if (brush == null)
                throw new ArgumentNullException("brush");
            if (border <= 0)
                throw new ArgumentException("Border must be greater than 0", "border");
            if (borderColors.Length == 0)
                throw new ArgumentException("Border requires at least 1 color", "borderColors");
            if (borderColors.Length > 1 && borderColors.Length != colorOffsets.Length)
                throw new ArgumentException("A border with more than 1 color requires a matching number of offsets", "colorOffsets");
            if (colorOffsets == null || colorOffsets.Length == 0)
                colorOffsets = new[] {(float)0};

            // Organize color fades from inner to outer
            var colors = borderColors
                .Select((c, i) => new KeyValuePair<float, Color>(colorOffsets[i], c))
                .OrderBy(c => c.Key)
                .ToArray();
            // Get bordered boundaries
            var offset = gfx.MeasureStringBoundaries(text, font).Location;
            var measure = gfx.MeasureStringBoundaries(text, font, border);

            using (var workImage = new Bitmap((int)measure.Width, (int)measure.Height))
            using (var gfxWork = Graphics.FromImage(workImage))
            {
                gfxWork.PageUnit = GraphicsUnit.Point;
                gfxWork.SmoothingMode = gfx.SmoothingMode;
                var path = new GraphicsPath();
                path.AddString(text, font.FontFamily, (int) font.Style, font.Size, new PointF((border-offset.X)*(float).75, (border-offset.Y)*(float).75), StringFormat.GenericDefault);

                // Fade the border from outer to inner.
                for (var b = border; b > 0; b--)
                {
                    var colorIndex = (float) 1/border*b;
                    var colorStart = colors.Length > 1 ? colors.Last(c => c.Key <= colorIndex) : colors.First();
                    var colorEnd = colors.Length > 1 ? colors.First(c => c.Key >= colorIndex) : colors.First();
                    var colorOffset = 1/Math.Max((float).0000001, colorEnd.Key - colorStart.Key)*(colorIndex - colorStart.Key);
                    var color = colorStart.Value.FadeTo(colorEnd.Value, colorOffset);

                    const float lineWidthOffset = (float) .65; // This is approximate
                    using (var pen = new Pen(color, b/lineWidthOffset) { LineJoin = LineJoin.Round })
                        gfxWork.DrawPath(pen, path);
                }

                // Draw the text
                gfxWork.FillPath(brush, path);
                var bounds = workImage.DetectPadding();
                var offsetX = ((measure.Width - bounds.Right) - bounds.X)/2;

                // Apply the generated image
                gfx.DrawImage(workImage, x + offsetX, y);
            }
        }
开发者ID:JackWangCUMT,项目名称:Bumpkit,代码行数:71,代码来源:FontEffects.cs

示例2: InitializeTopPixel

		private void InitializeTopPixel()
		{
			int tries;
			for (tries = 0; tries < 3; ++tries)
			{
				try
				{
					//get the first non-transparent pixel to determine offsets for name labels and damage counters
					Frame = NPCFrame.Standing;

					var frameTexture = _npcSheet.GetNPCTexture();
					var frameTextureData = new Color[frameTexture.Width * frameTexture.Height];
					frameTexture.GetData(frameTextureData);

					if (frameTextureData.All(x => x.A == 0))
						TopPixel = 0;
					else
					{
						var firstVisiblePixelIndex = frameTextureData.Select((color, index) => new { color, index })
																	 .Where(x => x.color.R != 0)
																	 .Select(x => x.index)
																	 .First();
						TopPixel = firstVisiblePixelIndex/frameTexture.Height;
					}
				} //this block throws errors sometimes..no idea why. It usually doesn't fail 3 times.
				catch (InvalidOperationException) { continue; }

				break;
			}

			if (tries >= 3)
				throw new InvalidOperationException("Something weird happened initializing this NPC.");
		}
开发者ID:Fallenoath,项目名称:EndlessClient,代码行数:33,代码来源:NPCRenderer.cs

示例3: CreateImage

        public IImage CreateImage(Color[] colors, int pixelWidth, double scale = 1)
        {
            var pixelHeight = colors.Length / pixelWidth;
            var palette = new BitmapPalette(colors.Select(c => c.GetColor()).ToList());
            var pixelFormat = PixelFormats.Indexed1;
            var dpi = DPI * scale;
            var stride = pixelWidth / pixelFormat.BitsPerPixel;
            var pixels = new byte[pixelHeight * stride];

            var bitmap = BitmapSource.Create(pixelWidth, pixelHeight, dpi, dpi, pixelFormat, palette, pixels, stride);
            return new ImageSourceImage(bitmap);
        }
开发者ID:zone117x,项目名称:NGraphics,代码行数:12,代码来源:PresentationFoundationPlatform.cs

示例4: ProcessPixel

		static public Color ProcessPixel(string mode, Color[] values)
		{
			int n = values.Length;
			Color ret;
			Color mean;
			Color stddev;
			float temp;
			switch (mode)
			{
				case "mean":
					ret = new Color();
					ret.R = values.GetRChannel().Average();
					ret.G = values.GetGChannel().Average();
					ret.B = values.GetBChannel().Average();
					return ret;
				case "stddev":
					mean = ProcessPixel("mean", values);
					ret = new Color();
					ret.R = values.GetRChannel().Select(i => (float)Math.Pow(i - mean.R, 2)).Average();
					ret.R = (float)Math.Sqrt(ret.R);
					if (ret.R < .000001) ret.R = .000001f;
					ret.G = values.GetGChannel().Select(i => (float)Math.Pow(i - mean.G, 2)).Average();
					ret.G = (float)Math.Sqrt(ret.G);
					if (ret.G < .000001) ret.G = .000001f;
					ret.B = values.GetBChannel().Select(i => (float)Math.Pow(i - mean.B, 2)).Average();
					ret.B = (float)Math.Sqrt(ret.B);
					if (ret.B < .000001) ret.B = .000001f;
					return ret;
				case "xi":
				{
					mean = ProcessPixel("mean", values);
					stddev = ProcessPixel("stddev", values);
					ret = new Color();
					temp = xi(values[0], mean, stddev);
					ret.R = ret.G = ret.B = temp;
					return ret;
				}
				case "CDi":
				{
					mean = ProcessPixel("mean", values);
					stddev = ProcessPixel("stddev", values);
					float Xi = ProcessPixel("xi", values).R;
					Func<Color, Color, Color, float, float> func =
						(I, U, Sig, xi) =>
						{
							return (float)Math.Sqrt(
								(float)Math.Pow((I.R - xi * U.R) / Sig.R, 2)
								+ (float)Math.Pow((I.G - xi * U.G) / Sig.G, 2)
								+ (float)Math.Pow((I.B - xi * U.B) / Sig.B, 2));
						};
					ret = new Color();
					temp = func(values[0], mean, stddev, Xi) / 10;
					ret.R = ret.G = ret.B = temp;
					return ret;
				}
				case "bi":
				{
					mean = ProcessPixel("mean", values);
					stddev = ProcessPixel("stddev", values);
					Func<Color, Color, Color, float, float> func =
						(I, U, Sig, xi) =>
						{
							return (float)Math.Sqrt(
								(float)Math.Pow((I.R - xi * U.R) / Sig.R, 2)
								+ (float)Math.Pow((I.G - xi * U.G) / Sig.G, 2)
								+ (float)Math.Pow((I.B - xi * U.B) / Sig.B, 2));
						};
					ret = new Color();
					temp = values
						.Select(i => new Tuple<Color, Color, Color, float>(i, mean, stddev, xi(i, mean, stddev)))
						.Select(i => func(i.Item1, i.Item2, i.Item3, i.Item4))
						.Sum(i => (float)Math.Pow(i, 2));
					temp = (float)Math.Sqrt(temp / n) / 10;
					ret.R = ret.G = ret.B = temp;
					return ret;
				}
				case "ai":
				{
					mean = ProcessPixel("mean", values);
					stddev = ProcessPixel("stddev", values);
					ret = new Color();
					temp = values
						.Select(i => new Tuple<Color, Color, Color>(i, mean, stddev))
						.Select(i => xi(i.Item1, i.Item2, i.Item3))
						.Sum(i => (float)Math.Pow(i - 1f, 2));
					temp = (float)Math.Sqrt(temp / n);
					//temp = temp / n;
					ret.R = ret.G = ret.B = temp;
					return ret;
				}
				default:
					throw new System.Exception("The passed mode was not valid!!");
			}
		}
开发者ID:lachesis,项目名称:backsub,代码行数:94,代码来源:Program.cs

示例5: startButton_Click

 private void startButton_Click(object sender, EventArgs e)
 {
     int numberOfPlayers = 0;
     int.TryParse(nrPlayers.Text, out numberOfPlayers);
     if (numberOfPlayers == 0)
     {
         MessageBox.Show("Alegeti numarul de jucatori!");
         return;
     }
     string[] names = new string[numberOfPlayers];
     Color[] colors = new Color[numberOfPlayers];
     for (int i = 0; i < int.Parse(nrPlayers.Text); i++)
     {
         names[i] = textBox[i].Text;
         if (names[i].Trim() == string.Empty)
         {
             MessageBox.Show("Completati numele jucatorilor!");
             return;
         }
         colors[i] = playerColor[i].BackColor;
     }
     //numarul de culori diferite trebuie sa fie egal cu numarul de jucatori
     var colorNo = colors.Select(p => p.Name).Distinct().Count();
     if (names.Count() != colorNo)
     {
         MessageBox.Show("Culorile nu pot fi la fel");
         return;
     }
     MainForm form = new MainForm(this, names, colors);
     form.Show();
     this.Visible = false;
 }
开发者ID:Flavius1924,项目名称:Piticot,代码行数:32,代码来源:PlayersForm.cs

示例6: DrawRainbowBand

        private void DrawRainbowBand(SpriteBatch batch, Vector2 origin, float angle, float scaleFactor, float extraIntensity)
        {
            DrawRainbowBand(batch, origin, angle, scaleFactor, RainbowBandTexture);

            if (extraIntensity > 0)
            {
                //Draw a white texture of the same size and shape on top of the rainbow we just drew

                var RainbowBandWhiteTexels = new Color[RainbowBandTexture.Height];
                RainbowBandTexture.GetData(RainbowBandWhiteTexels);

                RainbowBandWhiteTexels = RainbowBandWhiteTexels.Select(c => new Color(new Vector4(new Vector3(c.ToVector3().Length() > 0 ? extraIntensity : 0), 0))).ToArray();
                var RainbowBandWhiteTexture = new Texture2D(device, 1, RainbowBandWhiteTexels.Length);
                RainbowBandWhiteTexture.SetData(RainbowBandWhiteTexels);

                DrawRainbowBand(batch, origin, angle, scaleFactor, RainbowBandWhiteTexture);
            }
        }
开发者ID:noxo,项目名称:SecondRealityponyWinRT,代码行数:18,代码来源:Rainbow.cs

示例7: DisplayResultForColors

 void DisplayResultForColors(Color[][] colors)
 {
     colors
         .Select((c, i) => new { color = c, i })
         .Do(_ => Console.WriteLine(_.i))
         .SelectMany(_ => _.color)
         .Execute(c => Console.WriteLine(c.Name));
 }
开发者ID:sakapon,项目名称:Bellona.Analysis,代码行数:8,代码来源:ClusteringModelTest.cs


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