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


C# LinearGradientBrush类代码示例

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


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

示例1: OnPaint

    void OnPaint(object sender, PaintEventArgs e)
    {
        Graphics g = e.Graphics;

        Point pt1 = new Point(5, 5);
        Point pt2 = new Point(25, 25);
        Brush lg = new LinearGradientBrush(pt1, pt2, Color.Red, Color.Black);
        g.FillRectangle(lg, 20, 20, 300, 40);

        pt1 = new Point(5, 25);
        pt2 = new Point(20, 2);
        lg = new LinearGradientBrush(pt1, pt2, Color.Yellow, Color.Black);
        g.FillRectangle(lg, 20, 80, 300, 40);

        pt1 = new Point(5, 25);
        pt2 = new Point(2, 2);
        lg = new LinearGradientBrush(pt1, pt2, Color.Green, Color.Black);
        g.FillRectangle(lg, 20, 140, 300, 40);

        pt1 = new Point(25, 25);
        pt2 = new Point(15, 25);
        lg = new LinearGradientBrush(pt1, pt2, Color.Blue, Color.Black);
        g.FillRectangle(lg, 20, 200, 300, 40);

        pt1 = new Point(0, 10);
        pt2 = new Point(0, 20);
        lg = new LinearGradientBrush(pt1, pt2, Color.Orange, Color.Black);
        g.FillRectangle(lg, 20, 260, 300, 40);

        lg.Dispose();
        g.Dispose();
    }
开发者ID:sciruela,项目名称:MonoWinformsTutorial,代码行数:32,代码来源:gradients.cs

示例2: CreateCheckCodeImage

 private void CreateCheckCodeImage(string checkCode)
 {
     if ((checkCode != null) && (checkCode.Trim() != string.Empty))
     {
         Bitmap image = new Bitmap((int)Math.Ceiling((double)(checkCode.Length * 11.5)), 20);
         Graphics graphics = Graphics.FromImage(image);
         try
         {
             new Random();
             graphics.Clear(Color.White);
             Font font = new Font("Arial", 13f, FontStyle.Bold);
             LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Black, Color.DarkRed, 1.2f, true);
             graphics.DrawString(checkCode, font, brush, (float)2f, (float)2f);
             graphics.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
             MemoryStream stream = new MemoryStream();
             image.Save(stream, ImageFormat.Gif);
             base.Response.ClearContent();
             base.Response.ContentType = "image/Gif";
             base.Response.BinaryWrite(stream.ToArray());
         }
         finally
         {
             graphics.Dispose();
             image.Dispose();
         }
     }
 }
开发者ID:wangxu627,项目名称:WebBuss,代码行数:27,代码来源:yanzhengma.aspx.cs

示例3: Convert

        /// <summary>
        /// Converts the color of the supplied brush changing its luminosity by the given factor.
        /// </summary>
        /// <param name="value">The value that is produced by the binding target.</param>
        /// <param name="targetType">The type to convert to.</param>
        /// <param name="parameter">The factor used to adjust the luminosity (0..1).</param>
        /// <param name="culture">The culture to use in the converter (unused).</param>
        /// <returns>A converted value.</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
#endif
        {
            if (value == null) return null;
            if (parameter == null) return null;

            var factor = double.Parse(parameter.ToString(), CultureInfo.InvariantCulture);

            if (value is SolidColorBrush)
            {
                var color = ((SolidColorBrush)value).Color;
                var hlsColor = HlsColor.FromRgb(color);
                hlsColor.L *= factor;
                return new SolidColorBrush(hlsColor.ToRgb());
            }
            else if (value is LinearGradientBrush)
            {
                var gradientStops = new GradientStopCollection();
                foreach (var stop in ((LinearGradientBrush)value).GradientStops)
                {
                    var hlsColor = HlsColor.FromRgb(stop.Color);
                    hlsColor.L *= factor;
                    gradientStops.Add(new GradientStop() { Color = hlsColor.ToRgb(), Offset = stop.Offset });
                }

                var brush = new LinearGradientBrush(gradientStops, 0.0);
                return brush;
            }

            return value;
        }
开发者ID:alykhaled,项目名称:facebook-winclient-sdk,代码行数:39,代码来源:ColorLuminosityConverter.cs

示例4: Run

        public static void Run()
        {
            // ExStart:DrawingUsingGraphics
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages() + "SampleImage_out.bmp";

            // Create an instance of BmpOptions and set its various properties
            BmpOptions imageOptions = new BmpOptions();
            imageOptions.BitsPerPixel = 24;

            // Create an instance of FileCreateSource and assign it to Source property 
            imageOptions.Source = new FileCreateSource(dataDir, false);
            using (var image =  Image.Create(imageOptions, 500, 500))
            {
                var graphics = new Graphics(image);

                // Clear the image surface with white color and Create and initialize a Pen object with blue color
                graphics.Clear(Color.White);                
                var pen = new Pen(Color.Blue);

                // Draw Ellipse by defining the bounding rectangle of width 150 and height 100 also Draw a polygon using the LinearGradientBrush
                graphics.DrawEllipse(pen, new Rectangle(10, 10, 150, 100));
                using (var linearGradientBrush = new LinearGradientBrush(image.Bounds, Color.Red, Color.White, 45f))
                {
                    graphics.FillPolygon(linearGradientBrush, new[] { new Point(200, 200), new Point(400, 200), new Point(250, 350) });
                }
                image.Save();
            }
            // ExEnd:DrawingUsingGraphics
        }
开发者ID:aspose-imaging,项目名称:Aspose.Imaging-for-.NET,代码行数:30,代码来源:DrawingUsingGraphics.cs

示例5: CreateGradientBrush

		private static LinearGradientBrush CreateGradientBrush(Orientation orientation, params Color[] colors)
		{
		    var brush = new LinearGradientBrush();
			var negatedStops = 1 / (float) colors.Length;

			for (var i = 0; i < colors.Length; i++)
			{
				brush.GradientStops.Add(new GradientStop { Offset = negatedStops * i, Color = colors[i] });
			}

			// creating the full loop
			brush.GradientStops.Add(new GradientStop { Offset = negatedStops * colors.Length, Color = colors[0] });

            if (orientation == Orientation.Vertical)
            {
                brush.StartPoint = new Point(0, 1);
                brush.EndPoint = new Point();
            }
            else
            {
                brush.EndPoint = new Point(1, 0);
            }

            return brush;
        }
开发者ID:selaromdotnet,项目名称:Coding4FunToolkit,代码行数:25,代码来源:ColorSpace.cs

示例6: Page_Load

	protected void Page_Load(object sender, System.EventArgs e)
	{
		// Create the in-memory bitmap where you will draw the image. 
		Bitmap image = new Bitmap(300, 300);
		Graphics g = Graphics.FromImage(image);

		// Paint the background.
		g.FillRectangle(Brushes.White, 0, 0, 300, 300);

		// Create a brush to use.
		LinearGradientBrush myBrush;

		// Create variable to track the coordinates in the image.
		int y = 20;
		int x = 20;

		// Show a rectangle with each type of gradient.
		foreach (LinearGradientMode gradientStyle in System.Enum.GetValues(typeof(LinearGradientMode)))
		{
			myBrush = new LinearGradientBrush(new Rectangle(x, y, 100, 60), Color.Violet, Color.White, gradientStyle);
			g.FillRectangle(myBrush, x, y, 100, 60);
			g.DrawString(gradientStyle.ToString(), new Font("Tahoma", 8), Brushes.Black, 110 + x, y + 20);
			y += 70;
		}

		// Render the image to the HTML output stream.
		image.Save(Response.OutputStream,
			System.Drawing.Imaging.ImageFormat.Jpeg);

		g.Dispose();
		image.Dispose();
	}
开发者ID:Helen1987,项目名称:edu,代码行数:32,代码来源:GradientExamples.aspx.cs

示例7: D2Lines_Paint

        void D2Lines_Paint(object sender, PaintEventArgs e)
        {
            var lines = LineInfo.GenerateRandom(new Rectangle(Point.Empty, this.ClientSize));

            var sw = new Stopwatch();
            sw.Start();
            this.d2target.BeginDraw();
            this.d2target.Clear(Color.Black);

            foreach (var line in lines) {
                using (var gsc = new GradientStopCollection(this.d2target, new[]{
                    new GradientStop{ Position = 0f, Color = line.Ca },
                    new GradientStop{ Position = 1f, Color = line.Cb },
                }))
                using(var gb = new LinearGradientBrush(this.d2target, gsc, new LinearGradientBrushProperties{
                    StartPoint = line.Pa,
                    EndPoint = line.Pb,
                })) {
                    this.d2target.DrawLine(gb, line.Pa.X, line.Pa.Y, line.Pb.X, line.Pb.Y);
                }
            }

            this.d2target.EndDraw();
            sw.Stop();
            Program.Info(
                "{0}: {1} [ms], {2} [line], {3:.00} [line/ms], {4} * {5}",
                this.Text,
                sw.ElapsedMilliseconds,
                lines.Length,
                lines.Length / (float)sw.ElapsedMilliseconds,
                this.ClientSize.Width, this.ClientSize.Height
            );
        }
开发者ID:saiya,项目名称:111210_bentchmark_translucentLines,代码行数:33,代码来源:D2Lines.cs

示例8: SetTransform

		public void SetTransform (LinearGradientBrush widget, IMatrix transform)
		{
			var brush = ((BrushObject)widget.ControlObject);
			brush.Matrix = transform;
			var newmatrix = brush.InitialMatrix.Clone ();
			newmatrix.Multiply (transform.ToSD ());
			brush.Brush.Transform = newmatrix;
		}
开发者ID:gene-l-thomas,项目名称:Eto,代码行数:8,代码来源:LinearGradientBrushHandler.cs

示例9: PaintDocumentGradientBackground

            public static void PaintDocumentGradientBackground(Graphics graphics, Rectangle rectangle)
            {
                LinearGradientBrush BackgroundBrush = new LinearGradientBrush(rectangle, DefaultGradientUpper, DefaultGradientLower, LinearGradientMode.Vertical);

                graphics.Clear(DefaultGradientUpper);
                graphics.FillRectangle(BackgroundBrush, rectangle);
                BackgroundBrush.Dispose();
            }
开发者ID:ArchangelNexus,项目名称:Abstract-Design-Utility,代码行数:8,代码来源:StyleHelper.cs

示例10: Gradient

 public static void Gradient(Graphics g, Color c1, Color c2, int x, int y, int width, int height)
 {
     Rectangle R = new Rectangle(x, y, width, height);
     using (LinearGradientBrush T = new LinearGradientBrush(R, c1, c2, LinearGradientMode.Vertical))
     {
         g.FillRectangle(T, R);
     }
 }
开发者ID:uberm,项目名称:BitcoinMiner,代码行数:8,代码来源:Draw.cs

示例11: OnPaintBackground

 protected override void OnPaintBackground(PaintEventArgs e)
 {
     if (ClientRectangle.Width == 0 || ClientRectangle.Height == 0)
         return;
     using (var brush = new LinearGradientBrush(ClientRectangle,
                GradientFirstColor, GradientSecondColor, LinearGradientMode.Vertical))
     {
         e.Graphics.FillRectangle(brush, this.ClientRectangle);
     }
 }
开发者ID:mikadev001,项目名称:SublimeText-Overlay,代码行数:10,代码来源:GradientPanel.cs

示例12: CreatePic

    //绘制随机码
    private void CreatePic(string checkCode)
    {
        if (checkCode == null || checkCode.Trim() == String.Empty)
            return;
        Bitmap image = new Bitmap(checkCode.Length * 15 + 10, 30);
        Graphics g = Graphics.FromImage(image);
        try
        {
            //生成随机生成器
            Random random = new Random();
            //清空图片背景色
            g.Clear(Color.White);
            //画图片的背景噪音线
            for (int i = 0; i < 25; i++)
            {
                int x1 = random.Next(image.Width);
                int x2 = random.Next(image.Width);
                int y1 = random.Next(image.Height);
                int y2 = random.Next(image.Height);
                g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
            }
            //画图片字体和字号
            Font font = new Font("Arial", 15, (FontStyle.Bold | FontStyle.Italic));
            //初始化画刷
            LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.BlueViolet, Color.Crimson, 1.2f, true);
            g.DrawString(checkCode, font, brush, 2, 2);
            //画图片的前景噪音点
            for (int i = 0; i < 100; i++)
            {
                int x = random.Next(image.Width);
                int y = random.Next(image.Height);
                image.SetPixel(x, y, Color.FromArgb(random.Next()));
            }
            //画图片的边框线
            g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
            // 输出图像
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            //将图像保存到指定流
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            Response.ClearContent();
            //配置输出类型
            Response.ContentType = "image/Gif";
            //输入内容
            Response.BinaryWrite(ms.ToArray());

        }
        finally
        {
            //清空不需要的资源
            g.Dispose();
            image.Dispose();

        }
    }
开发者ID:ZRUIK,项目名称:SETC,代码行数:55,代码来源:CreatePic.aspx.cs

示例13: Blend

 public static void Blend(Graphics g, Color c1, Color c2, Color c3, float c, int d, int x, int y, int width, int height)
 {
     ColorBlend V = new ColorBlend(3);
     V.Colors = new Color[] { c1, c2, c3 };
     V.Positions = new float[] { 0F, c, 1F };
     Rectangle R = new Rectangle(x, y, width, height);
     using (LinearGradientBrush T = new LinearGradientBrush(R, c1, c1, (LinearGradientMode)d))
     {
         T.InterpolationColors = V;
         g.FillRectangle(T, R);
     }
 }
开发者ID:uberm,项目名称:BitcoinMiner,代码行数:12,代码来源:Draw.cs

示例14: PaintBackground

            public static void PaintBackground(Graphics graphics, Rectangle rectangle, Color colorLight, Color colorDark, Blend blend)
            {
                LinearGradientBrush BackgroundBrush = new LinearGradientBrush(rectangle, colorLight, colorDark, LinearGradientMode.Vertical);

                if (blend != null)
                {
                    BackgroundBrush.Blend = blend;
                }

                graphics.FillRectangle(BackgroundBrush, rectangle);
                BackgroundBrush.Dispose();
            }
开发者ID:ArchangelNexus,项目名称:Abstract-Design-Utility,代码行数:12,代码来源:StyleHelper.cs

示例15: OnPaint

    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        Graphics G = e.Graphics;
        base.OnPaint(e);
        G.Clear(this.BackColor);

        //| Drawing the main rectangle base.
        Rectangle MainRect = new Rectangle(0, 0, Width - 1, Height - 1);
        Rectangle MainHighlightRect = new Rectangle(1, 1, Width - 3, Height - 3);
        TextureBrush BGTextureBrush = new TextureBrush(D.CodeToImage(D.BGTexture), WrapMode.TileFlipXY);
        G.FillRectangle(BGTextureBrush, MainRect);

        if (OverlayCol != null)
        {
            G.FillRectangle(new SolidBrush(OverlayCol), MainRect);
        }

        //| Detail to the main rect's top & bottom gradients
        int GradientHeight = Height / 2;
        Rectangle ShineRect = new Rectangle(0, 0, Width, GradientHeight);
        Rectangle ShineRect2 = new Rectangle(0, GradientHeight, Width, GradientHeight);
        G.FillRectangle(new SolidBrush(Color.FromArgb(40, Pal.ColMed)), ShineRect);
        D.FillGradientBeam(G, Color.Transparent, Color.FromArgb(60, Pal.ColHighest), ShineRect, GradientAlignment.Vertical);
        D.FillGradientBeam(G, Color.Transparent, Color.FromArgb(30, Pal.ColHighest), ShineRect2, GradientAlignment.Vertical);
        if (DrawSeparator)
        {
            G.DrawLine(new Pen(Color.FromArgb(50, Color.Black)), new Point(1, ShineRect.Height), new Point(Width - 2, ShineRect.Height));
            G.DrawLine(new Pen(Color.FromArgb(35, Pal.ColHighest)), new Point(1, ShineRect.Height + 1), new Point(Width - 2, ShineRect.Height + 1));
            G.DrawLine(new Pen(Color.FromArgb(50, Color.Black)), new Point(1, ShineRect.Height + 2), new Point(Width - 2, ShineRect.Height + 2));
        }

        //| Goind back through and making the rect below the detail darker
        LinearGradientBrush DarkLGB = new LinearGradientBrush(MainRect, Color.FromArgb(20, Color.Black), Color.FromArgb(100, Color.Black), 90);
        G.FillRectangle(DarkLGB, MainRect);

        switch (State)
        {
            case MouseState.Over:
                G.FillRectangle(new SolidBrush(Color.FromArgb(30, Pal.ColHighest)), MainRect);
                break;
            case MouseState.Down:
                G.FillRectangle(new SolidBrush(Color.FromArgb(56, Color.Black)), MainRect);
                break;
        }

        G.DrawRectangle(new Pen(Color.FromArgb(40, Pal.ColHighest)), MainHighlightRect);
        G.DrawRectangle(Pens.Black, MainRect);
        if (!Enabled)
        {
            ForeColor = Color.FromArgb(146, 149, 152);
        }
        D.DrawTextWithShadow(G, new Rectangle(0, 0, Width, Height), Text, Font, HorizontalAlignment.Center, ForeColor, Color.Black);
    }
开发者ID:Hli4S,项目名称:TestMeApp,代码行数:53,代码来源:CustomTheme.cs


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