TextureBrush
Each property of the TextureBrush class is a Brush object that uses an image to fill the interior of a shape. This class cannot be inherited.
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Runtime.CompilerServices;
using Windows.Win32;
using Windows.Win32.Graphics.GdiPlus;
namespace System.Drawing
{
[NullableContext(1)]
[Nullable(0)]
public sealed class TextureBrush : Brush
{
public unsafe System.Drawing.Drawing2D.Matrix Transform {
get {
System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
PInvokeGdiPlus.GdipGetTextureTransform((GpTexture*)base.NativeBrush, matrix.NativeMatrix).ThrowIfFailed();
GC.KeepAlive(this);
return matrix;
}
set {
ArgumentNullException.ThrowIfNull(value, "value");
PInvokeGdiPlus.GdipSetTextureTransform((GpTexture*)base.NativeBrush, value.NativeMatrix).ThrowIfFailed();
GC.KeepAlive(this);
}
}
public unsafe System.Drawing.Drawing2D.WrapMode WrapMode {
get {
global::Windows.Win32.Graphics.GdiPlus.WrapMode result = default(global::Windows.Win32.Graphics.GdiPlus.WrapMode);
PInvokeGdiPlus.GdipGetTextureWrapMode((GpTexture*)base.NativeBrush, &result).ThrowIfFailed();
GC.KeepAlive(this);
return (System.Drawing.Drawing2D.WrapMode)result;
}
set {
if ((value < System.Drawing.Drawing2D.WrapMode.Tile || value > System.Drawing.Drawing2D.WrapMode.Clamp) ? true : false)
throw new InvalidEnumArgumentException("value", (int)value, typeof(System.Drawing.Drawing2D.WrapMode));
PInvokeGdiPlus.GdipSetTextureWrapMode((GpTexture*)base.NativeBrush, (global::Windows.Win32.Graphics.GdiPlus.WrapMode)value).ThrowIfFailed();
GC.KeepAlive(this);
}
}
public unsafe Image Image {
get {
GpImage* nativeImage = default(GpImage*);
PInvokeGdiPlus.GdipGetTextureImage((GpTexture*)base.NativeBrush, &nativeImage).ThrowIfFailed();
GC.KeepAlive(this);
return Image.CreateImageObject(nativeImage);
}
}
public TextureBrush(Image bitmap)
: this(bitmap, System.Drawing.Drawing2D.WrapMode.Tile)
{
}
public unsafe TextureBrush(Image image, System.Drawing.Drawing2D.WrapMode wrapMode)
{
ArgumentNullException.ThrowIfNull(image, "image");
if ((wrapMode < System.Drawing.Drawing2D.WrapMode.Tile || wrapMode > System.Drawing.Drawing2D.WrapMode.Clamp) ? true : false)
throw new InvalidEnumArgumentException("wrapMode", (int)wrapMode, typeof(System.Drawing.Drawing2D.WrapMode));
GpTexture* nativeBrushInternal = default(GpTexture*);
PInvokeGdiPlus.GdipCreateTexture(image.Pointer(), (global::Windows.Win32.Graphics.GdiPlus.WrapMode)wrapMode, &nativeBrushInternal).ThrowIfFailed();
GC.KeepAlive(image);
SetNativeBrushInternal((GpBrush*)nativeBrushInternal);
}
public unsafe TextureBrush(Image image, System.Drawing.Drawing2D.WrapMode wrapMode, RectangleF dstRect)
{
ArgumentNullException.ThrowIfNull(image, "image");
if ((wrapMode < System.Drawing.Drawing2D.WrapMode.Tile || wrapMode > System.Drawing.Drawing2D.WrapMode.Clamp) ? true : false)
throw new InvalidEnumArgumentException("wrapMode", (int)wrapMode, typeof(System.Drawing.Drawing2D.WrapMode));
GpTexture* nativeBrushInternal = default(GpTexture*);
PInvokeGdiPlus.GdipCreateTexture2(image.Pointer(), (global::Windows.Win32.Graphics.GdiPlus.WrapMode)wrapMode, dstRect.X, dstRect.Y, dstRect.Width, dstRect.Height, &nativeBrushInternal).ThrowIfFailed();
GC.KeepAlive(image);
SetNativeBrushInternal((GpBrush*)nativeBrushInternal);
}
public TextureBrush(Image image, System.Drawing.Drawing2D.WrapMode wrapMode, Rectangle dstRect)
: this(image, wrapMode, (RectangleF)dstRect)
{
}
public TextureBrush(Image image, RectangleF dstRect)
: this(image, dstRect, null)
{
}
public unsafe TextureBrush(Image image, RectangleF dstRect, [Nullable(2)] ImageAttributes imageAttr)
{
ArgumentNullException.ThrowIfNull(image, "image");
GpTexture* nativeBrushInternal = default(GpTexture*);
PInvokeGdiPlus.GdipCreateTextureIA(image.Pointer(), (GpImageAttributes*)(long)((imageAttr == null) ? ((IntPtr)(void*)null) : ((IntPtr)imageAttr._nativeImageAttributes)), dstRect.X, dstRect.Y, dstRect.Width, dstRect.Height, &nativeBrushInternal).ThrowIfFailed();
SetNativeBrushInternal((GpBrush*)nativeBrushInternal);
GC.KeepAlive(image);
GC.KeepAlive(imageAttr);
}
public TextureBrush(Image image, Rectangle dstRect)
: this(image, dstRect, null)
{
}
public TextureBrush(Image image, Rectangle dstRect, [Nullable(2)] ImageAttributes imageAttr)
: this(image, (RectangleF)dstRect, imageAttr)
{
}
[NullableContext(0)]
internal unsafe TextureBrush(GpTexture* nativeBrush)
{
SetNativeBrushInternal((GpBrush*)nativeBrush);
}
public unsafe override object Clone()
{
GpBrush* nativeBrush = default(GpBrush*);
PInvokeGdiPlus.GdipCloneBrush(base.NativeBrush, &nativeBrush).ThrowIfFailed();
GC.KeepAlive(this);
return new TextureBrush((GpTexture*)nativeBrush);
}
public unsafe void ResetTransform()
{
PInvokeGdiPlus.GdipResetTextureTransform((GpTexture*)base.NativeBrush).ThrowIfFailed();
GC.KeepAlive(this);
}
public void MultiplyTransform(System.Drawing.Drawing2D.Matrix matrix)
{
MultiplyTransform(matrix, System.Drawing.Drawing2D.MatrixOrder.Prepend);
}
public unsafe void MultiplyTransform(System.Drawing.Drawing2D.Matrix matrix, System.Drawing.Drawing2D.MatrixOrder order)
{
ArgumentNullException.ThrowIfNull(matrix, "matrix");
if (matrix.NativeMatrix != null) {
PInvokeGdiPlus.GdipMultiplyTextureTransform((GpTexture*)base.NativeBrush, matrix.NativeMatrix, (global::Windows.Win32.Graphics.GdiPlus.MatrixOrder)order).ThrowIfFailed();
GC.KeepAlive(this);
GC.KeepAlive(matrix);
}
}
public void TranslateTransform(float dx, float dy)
{
TranslateTransform(dx, dy, System.Drawing.Drawing2D.MatrixOrder.Prepend);
}
public unsafe void TranslateTransform(float dx, float dy, System.Drawing.Drawing2D.MatrixOrder order)
{
PInvokeGdiPlus.GdipTranslateTextureTransform((GpTexture*)base.NativeBrush, dx, dy, (global::Windows.Win32.Graphics.GdiPlus.MatrixOrder)order).ThrowIfFailed();
GC.KeepAlive(this);
}
public void ScaleTransform(float sx, float sy)
{
ScaleTransform(sx, sy, System.Drawing.Drawing2D.MatrixOrder.Prepend);
}
public unsafe void ScaleTransform(float sx, float sy, System.Drawing.Drawing2D.MatrixOrder order)
{
PInvokeGdiPlus.GdipScaleTextureTransform((GpTexture*)base.NativeBrush, sx, sy, (global::Windows.Win32.Graphics.GdiPlus.MatrixOrder)order).ThrowIfFailed();
GC.KeepAlive(this);
}
public void RotateTransform(float angle)
{
RotateTransform(angle, System.Drawing.Drawing2D.MatrixOrder.Prepend);
}
public unsafe void RotateTransform(float angle, System.Drawing.Drawing2D.MatrixOrder order)
{
PInvokeGdiPlus.GdipRotateTextureTransform((GpTexture*)base.NativeBrush, angle, (global::Windows.Win32.Graphics.GdiPlus.MatrixOrder)order).ThrowIfFailed();
GC.KeepAlive(this);
}
}
}