首页 > 其他 > 详细

GDI笔刷

时间:2019-12-03 15:37:47      阅读:92      评论:0      收藏:0      [点我收藏+]

一,solidBrush

纯色填充

利用窗体的paint事件

技术分享图片
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Brush br = new SolidBrush(Color.Red);
            g.FillRectangle(br,10,10,100,100);
            g.Dispose();
         }
Form1_Paint

二,TextureBrush

利用位图填充

首先添加一张图片

技术分享图片

 

技术分享图片
using System.IO;
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            string path = @"F:\Lianxi\App1\App1\Img\龙猫.jpg";
            Graphics g = e.Graphics;

            Bitmap img;
            if (File.Exists(path))
            {
                img = new Bitmap(path);
                Brush br = new TextureBrush(img);
                g.FillRectangle(br, 30, 30, 500, 400);
            }
            else
            {
                MessageBox.Show("找不到要填充的图片","提示",MessageBoxButtons.OK);  
            }

            g.Dispose();//释放Graphics所使用的资源
         }
Form1_Paint

 

 三,LinearGradientBrush

线性渐变

技术分享图片
using System.Drawing.Drawing2D;
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            LinearGradientBrush lgb = new LinearGradientBrush(new Point(0, 140), new Point(280, 140), Color.Red, Color.White);
            g.FillEllipse(lgb, 0, 140, 280, 120);
            lgb.Dispose();
            g.Dispose();
        }
Form1_Paint

 

四,PathGradientBrush 

中心点渐变

技术分享图片
using System.Drawing.Drawing2D;
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            GraphicsPath gp = new GraphicsPath();
            gp.AddEllipse(0, 80, 280, 120);
            PathGradientBrush pgb = new PathGradientBrush(gp);
            pgb.CenterColor = Color.FromArgb(0, 255, 255, 20);
            Color[] colors = { Color.FromArgb(255, 0, 255, 0)};//FromArgb(透明度,R,G,B)
            pgb.SurroundColors = colors;
            e.Graphics.FillEllipse(pgb, 0, 80, 280, 120);
            pgb.Dispose();
        }
Form1_Paint

 

五,HatchBrush

以条案填充

技术分享图片

 

 

技术分享图片
using System.Drawing.Drawing2D;
       private void Form1_Paint(object sender, PaintEventArgs e)
        {
            HatchBrush hatchBrush = new HatchBrush(HatchStyle.HorizontalBrick,Color.White,Color.Red);
            e.Graphics.FillRectangle(hatchBrush,10,10,100,100);
            e.Graphics.Dispose();
        }
Form1_Paint

 

GDI笔刷

原文:https://www.cnblogs.com/Luck1996/p/11976802.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!