using (Bitmap image = new Bitmap("texture.png")) { TextureBrush brush = new TextureBrush(image); // use the brush to draw shapes or fill areas } // the brush is automatically disposed when the using block ends
Bitmap image = new Bitmap("texture.png"); TextureBrush brush = new TextureBrush(image); // use the brush to draw shapes or fill areas brush.Dispose(); // release the resources used by the brush image.Dispose(); // also dispose of the underlying bitmapIn both examples, the TextureBrush class is used to fill the interior of a shape with a texture image, such as a background pattern. The Dispose method is called to release the resources used by the brush after it's no longer needed. These examples require the System.Drawing package library in C#.