TexturedBrush Class
The TexturedBrush class is used to fill shapes with a specified image. It allows you to tile an image within a defined area, creating visually rich and complex fills.
Inheritance
Object → Brush → TexturedBrush
Syntax
public sealed class TexturedBrush : Brush
Constructors
TexturedBrush(Image image)
Initializes a new instance of the TexturedBrush class using the specified Image object.
Parameters:
| Name | Type | Description |
|---|---|---|
image |
Image | The Image object to use for the texture. |
TexturedBrush(Image image, WrapMode wrapMode)
Initializes a new instance of the TexturedBrush class using the specified Image object and WrapMode.
Parameters:
| Name | Type | Description |
|---|---|---|
image |
Image | The Image object to use for the texture. |
wrapMode |
WrapMode | A WrapMode enumeration value that specifies how the image is tiled. |
Methods
SetWrapMode(WrapMode wrapMode)
Sets the tiling mode of the brush.
Parameters:
| Name | Type | Description |
|---|---|---|
wrapMode |
WrapMode | A WrapMode enumeration value that specifies how the image is tiled. |
GetWrapMode()
Gets the tiling mode of the brush.
Returns:
A WrapMode enumeration value that specifies how the image is tiled.
Dispose()
Releases all resources used by this TexturedBrush object.
Properties
Remarks
The TexturedBrush class is particularly useful for creating backgrounds with repeating patterns, borders with image elements, or complex artistic fills where a single color is not sufficient.
Example
The following C# code demonstrates how to create and use a TexturedBrush to fill a rectangle with a tiled image.
using System.Drawing;
using System.Drawing.Imaging;
// Assume 'graphics' is a valid Graphics object and 'myImage' is a loaded Bitmap
using (Bitmap myImage = new Bitmap("path/to/your/texture.png"))
{
using (TexturedBrush texturedBrush = new TexturedBrush(myImage, WrapMode.TileFlipXY))
{
// Fill a rectangle with the textured brush
graphics.FillRectangle(texturedBrush, 50, 50, 200, 150);
}
}