二、画刷的使用
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
public Form1()
{
InitializeComponent();
comboBox1.SelectedIndex = 0;
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap bp = new Bitmap("1.jpg");
TextureBrush tb = new TextureBrush(bp);
Graphics g = this.CreateGraphics();
g.FillRectangle(tb, this.ClientRectangle);
bp.Dispose();
tb.Dispose();
g.Dispose();
}
private void button2_Click(object sender, EventArgs e)
{
Bitmap bp = new Bitmap("1.jpg");
TextureBrush tb = new TextureBrush(bp, new Rectangle(0, 0, 100, 100));
Graphics g = this.CreateGraphics();
switch (comboBox1.SelectedItem.ToString().Trim())
{
case "Clamp":
tb.WrapMode = WrapMode.Clamp;
g.FillRectangle(tb, this.ClientRectangle);
bp.Dispose();
tb.Dispose();
g.Dispose();
break;
case "Tile":
tb.WrapMode = WrapMode.Tile;
g.FillRectangle(tb, this.ClientRectangle);
bp.Dispose();
tb.Dispose();
g.Dispose();
break;
case "TileFlipX":
tb.WrapMode = WrapMode.TileFlipX;
g.FillRectangle(tb, this.ClientRectangle);
bp.Dispose();
tb.Dispose();
g.Dispose();
break;
case "TileFlipXY":
tb.WrapMode = WrapMode.TileFlipXY;
g.FillRectangle(tb, this.ClientRectangle);
bp.Dispose();
t

本文详细介绍了GDI+中画刷的使用,包括TextureBrush、ColorMatrix、LinearGradientBrush、GraphicsPath和HatchBrush等。通过示例代码展示了如何实现不同类型的填充效果,如平铺、渐变、颜色矩阵变换以及各种图案填充。
最低0.47元/天 解锁文章
1438





