TextureBrush对象用于基于光栅的图像来填充图形。它使用一个来自图像文件如.bmp、.jpg或.png的图像。使用Bitmap类可以从文件中获取图像,Bitmap类时Image类的一个子类,为此,可以使用如下代码用图案填充:

1 private void Form1_Paint(object sender, PaintEventArgs e)
2 {
3 Graphics g = e.Graphics;
4 Bitmap bmp = new Bitmap("D:\\Images\\alphabet.gif");
5 TextureBrush tb = new TextureBrush(bmp);
6
7 g.FillRectangle(tb,20,20,200,70);
8 bmp.Dispose();
9 tb.Dispose();
10 }

得到的图像为:

C#--GDI+ TextureBrush画刷

把图像中的一个选区作为平铺图片,重载TextureBrush构造函数为允许选择图像的一部分用作TextureBrush填充图形是的平铺图片。如:

1 private void Form1_Paint(object sender, PaintEventArgs e)
2 {
3 Graphics g = e.Graphics;
4 Bitmap bmp = new Bitmap("D:\\Images\\alphabet.gif");
5 TextureBrush tb = new TextureBrush(bmp,new Rectangle(0,0,25,25));
6
7 g.FillRectangle(tb,20,20,200,70);
8 g.FillRectangle(tb, 45, 45, 70, 150);
9 bmp.Dispose();
10 tb.Dispose();
11 }

图像为:

C#--GDI+ TextureBrush画刷

 

相关文章:

  • 2022-12-23
  • 2021-11-24
  • 2022-12-23
  • 2021-09-06
  • 2021-09-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-20
  • 2022-01-25
  • 2022-12-23
  • 2022-12-23
  • 2022-02-04
  • 2022-12-23
  • 2021-06-04
相关资源
相似解决方案