Graphics
public sealed class Graphics : MarshalByRefObject, IDisposable, IDeviceContext, IGraphics, IGraphicsContextInfo, IPointer<GpGraphics>, IHdcContext
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Imaging.Effects;
using System.Drawing.Text;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.Graphics.Gdi;
using Windows.Win32.Graphics.GdiPlus;
using Windows.Win32.UI.WindowsAndMessaging;
namespace System.Drawing
{
[NullableContext(1)]
[Nullable(0)]
public sealed class Graphics : MarshalByRefObject, IDisposable, IDeviceContext, IGraphics, IGraphicsContextInfo, IPointer<GpGraphics>, IHdcContext
{
[NullableContext(0)]
public delegate bool DrawImageAbort (IntPtr callbackdata);
[NullableContext(0)]
public delegate bool EnumerateMetafileProc (System.Drawing.Imaging.EmfPlusRecordType recordType, int flags, int dataSize, IntPtr data, PlayRecordCallback callbackData);
[NullableContext(0)]
private unsafe delegate BOOL NativeEnumerateMetafileProc (System.Drawing.Imaging.EmfPlusRecordType recordType, uint flags, uint dataSize, byte* data, void* callbackData);
[NullableContext(0)]
private sealed class EnumerateMetafileDataAdapter : IDisposable
{
[Nullable(1)]
private readonly EnumerateMetafileProc _callback;
[Nullable(1)]
private readonly NativeEnumerateMetafileProc _nativeCallback;
public IntPtr NativeCallback { get; }
[NullableContext(1)]
public unsafe EnumerateMetafileDataAdapter(EnumerateMetafileProc callback)
{
_callback = callback;
_nativeCallback = CallBack;
NativeCallback = Marshal.GetFunctionPointerForDelegate(_nativeCallback);
}
private unsafe BOOL CallBack(System.Drawing.Imaging.EmfPlusRecordType recordType, uint flags, uint dataSize, byte* data, void* callbackData)
{
return _callback(recordType, (int)flags, (int)dataSize, (IntPtr)data, null);
}
public unsafe void Dispose()
{
GC.KeepAlive(_callback);
GC.KeepAlive(_nativeCallback);
}
}
[Nullable(2)]
private GraphicsContext _previousContext;
private static readonly Lock s_syncObject = new Lock();
[Nullable(2)]
private object _printingHelper;
private static HPALETTE s_halftonePalette;
[Nullable(2)]
private Image _backingImage;
private HDC _nativeHdc;
[Nullable(0)]
[field: Nullable(0)]
internal unsafe GpGraphics* NativeGraphics {
[NullableContext(0)]
get;
[NullableContext(0)]
private set;
}
unsafe IntPtr IPointer<GpGraphics>.Pointer {
get {
return (IntPtr)NativeGraphics;
}
}
public unsafe Region Clip {
get {
Region region = new Region();
CheckStatus(PInvokeGdiPlus.GdipGetClip(NativeGraphics, region.NativeRegion));
return region;
}
set {
SetClip(value, System.Drawing.Drawing2D.CombineMode.Replace);
}
}
public unsafe RectangleF ClipBounds {
get {
RectF rect = default(RectF);
CheckStatus(PInvokeGdiPlus.GdipGetClipBounds(NativeGraphics, &rect));
return rect;
}
}
public unsafe System.Drawing.Drawing2D.CompositingMode CompositingMode {
get {
global::Windows.Win32.Graphics.GdiPlus.CompositingMode result = default(global::Windows.Win32.Graphics.GdiPlus.CompositingMode);
CheckStatus(PInvokeGdiPlus.GdipGetCompositingMode(NativeGraphics, &result));
return (System.Drawing.Drawing2D.CompositingMode)result;
}
set {
if ((value < System.Drawing.Drawing2D.CompositingMode.SourceOver || value > System.Drawing.Drawing2D.CompositingMode.SourceCopy) ? true : false)
throw new InvalidEnumArgumentException("value", (int)value, typeof(System.Drawing.Drawing2D.CompositingMode));
CheckStatus(PInvokeGdiPlus.GdipSetCompositingMode(NativeGraphics, (global::Windows.Win32.Graphics.GdiPlus.CompositingMode)value));
}
}
public unsafe System.Drawing.Drawing2D.CompositingQuality CompositingQuality {
get {
global::Windows.Win32.Graphics.GdiPlus.CompositingQuality result = default(global::Windows.Win32.Graphics.GdiPlus.CompositingQuality);
CheckStatus(PInvokeGdiPlus.GdipGetCompositingQuality(NativeGraphics, &result));
return (System.Drawing.Drawing2D.CompositingQuality)result;
}
set {
if ((value < System.Drawing.Drawing2D.CompositingQuality.Invalid || value > System.Drawing.Drawing2D.CompositingQuality.AssumeLinear) ? true : false)
throw new InvalidEnumArgumentException("value", (int)value, typeof(System.Drawing.Drawing2D.CompositingQuality));
CheckStatus(PInvokeGdiPlus.GdipSetCompositingQuality(NativeGraphics, (global::Windows.Win32.Graphics.GdiPlus.CompositingQuality)value));
}
}
public unsafe float DpiX {
get {
float result = default(float);
CheckStatus(PInvokeGdiPlus.GdipGetDpiX(NativeGraphics, &result));
return result;
}
}
public unsafe float DpiY {
get {
float result = default(float);
CheckStatus(PInvokeGdiPlus.GdipGetDpiY(NativeGraphics, &result));
return result;
}
}
public unsafe System.Drawing.Drawing2D.InterpolationMode InterpolationMode {
get {
global::Windows.Win32.Graphics.GdiPlus.InterpolationMode result = default(global::Windows.Win32.Graphics.GdiPlus.InterpolationMode);
CheckStatus(PInvokeGdiPlus.GdipGetInterpolationMode(NativeGraphics, &result));
return (System.Drawing.Drawing2D.InterpolationMode)result;
}
set {
if ((value < System.Drawing.Drawing2D.InterpolationMode.Invalid || value > System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic) ? true : false)
throw new InvalidEnumArgumentException("value", (int)value, typeof(System.Drawing.Drawing2D.InterpolationMode));
CheckStatus(PInvokeGdiPlus.GdipSetInterpolationMode(NativeGraphics, (global::Windows.Win32.Graphics.GdiPlus.InterpolationMode)value));
}
}
public unsafe bool IsClipEmpty {
get {
BOOL value = default(BOOL);
CheckStatus(PInvokeGdiPlus.GdipIsClipEmpty(NativeGraphics, &value));
return value;
}
}
public unsafe bool IsVisibleClipEmpty {
get {
BOOL value = default(BOOL);
CheckStatus(PInvokeGdiPlus.GdipIsVisibleClipEmpty(NativeGraphics, &value));
return value;
}
}
public unsafe float PageScale {
get {
float result = default(float);
CheckStatus(PInvokeGdiPlus.GdipGetPageScale(NativeGraphics, &result));
return result;
}
set {
CheckStatus(PInvokeGdiPlus.GdipSetPageScale(NativeGraphics, value));
}
}
public unsafe GraphicsUnit PageUnit {
get {
Unit result = default(Unit);
CheckStatus(PInvokeGdiPlus.GdipGetPageUnit(NativeGraphics, &result));
return (GraphicsUnit)result;
}
set {
if ((value < GraphicsUnit.World || value > GraphicsUnit.Millimeter) ? true : false)
throw new InvalidEnumArgumentException("value", (int)value, typeof(GraphicsUnit));
CheckStatus(PInvokeGdiPlus.GdipSetPageUnit(NativeGraphics, (Unit)value));
}
}
public unsafe System.Drawing.Drawing2D.PixelOffsetMode PixelOffsetMode {
get {
global::Windows.Win32.Graphics.GdiPlus.PixelOffsetMode result = default(global::Windows.Win32.Graphics.GdiPlus.PixelOffsetMode);
CheckStatus(PInvokeGdiPlus.GdipGetPixelOffsetMode(NativeGraphics, &result));
return (System.Drawing.Drawing2D.PixelOffsetMode)result;
}
set {
if ((value < System.Drawing.Drawing2D.PixelOffsetMode.Invalid || value > System.Drawing.Drawing2D.PixelOffsetMode.Half) ? true : false)
throw new InvalidEnumArgumentException("value", (int)value, typeof(System.Drawing.Drawing2D.PixelOffsetMode));
CheckStatus(PInvokeGdiPlus.GdipSetPixelOffsetMode(NativeGraphics, (global::Windows.Win32.Graphics.GdiPlus.PixelOffsetMode)value));
}
}
public unsafe Point RenderingOrigin {
get {
int x = default(int);
int y = default(int);
CheckStatus(PInvokeGdiPlus.GdipGetRenderingOrigin(NativeGraphics, &x, &y));
return new Point(x, y);
}
set {
CheckStatus(PInvokeGdiPlus.GdipSetRenderingOrigin(NativeGraphics, value.X, value.Y));
}
}
public unsafe System.Drawing.Drawing2D.SmoothingMode SmoothingMode {
get {
global::Windows.Win32.Graphics.GdiPlus.SmoothingMode result = default(global::Windows.Win32.Graphics.GdiPlus.SmoothingMode);
CheckStatus(PInvokeGdiPlus.GdipGetSmoothingMode(NativeGraphics, &result));
return (System.Drawing.Drawing2D.SmoothingMode)result;
}
set {
if ((value < System.Drawing.Drawing2D.SmoothingMode.Invalid || value > System.Drawing.Drawing2D.SmoothingMode.AntiAlias) ? true : false)
throw new InvalidEnumArgumentException("value", (int)value, typeof(System.Drawing.Drawing2D.SmoothingMode));
CheckStatus(PInvokeGdiPlus.GdipSetSmoothingMode(NativeGraphics, (global::Windows.Win32.Graphics.GdiPlus.SmoothingMode)value));
}
}
public unsafe int TextContrast {
get {
uint result = default(uint);
CheckStatus(PInvokeGdiPlus.GdipGetTextContrast(NativeGraphics, &result));
return (int)result;
}
set {
CheckStatus(PInvokeGdiPlus.GdipSetTextContrast(NativeGraphics, (uint)value));
}
}
public unsafe System.Drawing.Text.TextRenderingHint TextRenderingHint {
get {
global::Windows.Win32.Graphics.GdiPlus.TextRenderingHint result = default(global::Windows.Win32.Graphics.GdiPlus.TextRenderingHint);
CheckStatus(PInvokeGdiPlus.GdipGetTextRenderingHint(NativeGraphics, &result));
return (System.Drawing.Text.TextRenderingHint)result;
}
set {
if ((value < System.Drawing.Text.TextRenderingHint.SystemDefault || value > System.Drawing.Text.TextRenderingHint.ClearTypeGridFit) ? true : false)
throw new InvalidEnumArgumentException("value", (int)value, typeof(System.Drawing.Text.TextRenderingHint));
CheckStatus(PInvokeGdiPlus.GdipSetTextRenderingHint(NativeGraphics, (global::Windows.Win32.Graphics.GdiPlus.TextRenderingHint)value));
}
}
public unsafe System.Drawing.Drawing2D.Matrix Transform {
get {
System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
CheckStatus(PInvokeGdiPlus.GdipGetWorldTransform(NativeGraphics, matrix.NativeMatrix));
return matrix;
}
set {
CheckStatus(PInvokeGdiPlus.GdipSetWorldTransform(NativeGraphics, value.NativeMatrix));
GC.KeepAlive(value);
}
}
public unsafe Matrix3x2 TransformElements {
get {
global::Windows.Win32.Graphics.GdiPlus.Matrix* ptr = default(global::Windows.Win32.Graphics.GdiPlus.Matrix*);
CheckStatus(PInvokeGdiPlus.GdipCreateMatrix(&ptr));
try {
CheckStatus(PInvokeGdiPlus.GdipGetWorldTransform(NativeGraphics, ptr));
Matrix3x2 result = default(Matrix3x2);
CheckStatus(PInvokeGdiPlus.GdipGetMatrixElements(ptr, (float*)(&result)));
return result;
} finally {
if (ptr != null)
PInvokeGdiPlus.GdipDeleteMatrix(ptr);
}
}
set {
global::Windows.Win32.Graphics.GdiPlus.Matrix* ptr = System.Drawing.Drawing2D.Matrix.CreateNativeHandle(value);
try {
CheckStatus(PInvokeGdiPlus.GdipSetWorldTransform(NativeGraphics, ptr));
} finally {
if (ptr != null)
PInvokeGdiPlus.GdipDeleteMatrix(ptr);
}
}
}
[Nullable(2)]
internal object PrintingHelper {
[NullableContext(2)]
get {
return _printingHelper;
}
[NullableContext(2)]
set {
_printingHelper = value;
}
}
public unsafe RectangleF VisibleClipBounds {
get {
PrintPreviewGraphics printPreviewGraphics = PrintingHelper as PrintPreviewGraphics;
if (printPreviewGraphics != null)
return printPreviewGraphics.VisibleClipBounds;
RectF rect = default(RectF);
CheckStatus(PInvokeGdiPlus.GdipGetVisibleClipBounds(NativeGraphics, &rect));
return rect;
}
}
[NullableContext(0)]
private unsafe Graphics(GpGraphics* gdipNativeGraphics)
{
if (gdipNativeGraphics == null)
throw new ArgumentNullException("gdipNativeGraphics");
NativeGraphics = gdipNativeGraphics;
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
public static Graphics FromHdc(IntPtr hdc)
{
if (hdc != (IntPtr)0)
return FromHdcInternal(hdc);
throw new ArgumentNullException("hdc");
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
public unsafe static Graphics FromHdcInternal(IntPtr hdc)
{
GpGraphics* gdipNativeGraphics = default(GpGraphics*);
Gdip.CheckStatus(PInvokeGdiPlus.GdipCreateFromHDC((HDC)hdc, &gdipNativeGraphics));
return new Graphics(gdipNativeGraphics);
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
public unsafe static Graphics FromHdc(IntPtr hdc, IntPtr hdevice)
{
GpGraphics* gdipNativeGraphics = default(GpGraphics*);
Gdip.CheckStatus(PInvokeGdiPlus.GdipCreateFromHDC2((HDC)hdc, (HANDLE)hdevice, &gdipNativeGraphics));
return new Graphics(gdipNativeGraphics);
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
public static Graphics FromHwnd(IntPtr hwnd)
{
return FromHwndInternal(hwnd);
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
public unsafe static Graphics FromHwndInternal(IntPtr hwnd)
{
GdiPlusInitialization.EnsureInitialized();
GpGraphics* gdipNativeGraphics = default(GpGraphics*);
Gdip.CheckStatus(PInvokeGdiPlus.GdipCreateFromHWND((HWND)hwnd, &gdipNativeGraphics));
return new Graphics(gdipNativeGraphics);
}
public unsafe static Graphics FromImage(Image image)
{
ArgumentNullException.ThrowIfNull(image, "image");
if ((image.PixelFormat & System.Drawing.Imaging.PixelFormat.Indexed) != 0)
throw new ArgumentException(System.SR.GdiplusCannotCreateGraphicsFromIndexedPixelFormat, "image");
GpGraphics* gdipNativeGraphics = default(GpGraphics*);
Gdip.CheckStatus(PInvokeGdiPlus.GdipGetImageGraphicsContext(image.Pointer(), &gdipNativeGraphics));
GC.KeepAlive(image);
return new Graphics(gdipNativeGraphics) {
_backingImage = image
};
}
[EditorBrowsable(EditorBrowsableState.Never)]
public unsafe void ReleaseHdcInternal(IntPtr hdc)
{
CheckStatus(Gdip.Initialized ? PInvokeGdiPlus.GdipReleaseDC(NativeGraphics, (HDC)hdc) : Status.Ok);
_nativeHdc = HDC.Null;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private unsafe void Dispose(bool disposing)
{
if (disposing) {
while (_previousContext != null) {
GraphicsContext previous = _previousContext.Previous;
_previousContext.Dispose();
_previousContext = previous;
}
HdcHandle hdcHandle = PrintingHelper as HdcHandle;
if (hdcHandle != null) {
hdcHandle.Dispose();
_printingHelper = null;
}
}
if (!_nativeHdc.IsNull)
ReleaseHdc();
if (NativeGraphics != null) {
if (Gdip.Initialized)
PInvokeGdiPlus.GdipDeleteGraphics(NativeGraphics);
NativeGraphics = null;
}
}
~Graphics()
{
Dispose(false);
}
HDC IHdcContext.GetHdc()
{
return (HDC)GetHdc();
}
public unsafe IntPtr GetHdc()
{
HDC nativeHdc = default(HDC);
CheckStatus(PInvokeGdiPlus.GdipGetDC(NativeGraphics, &nativeHdc));
_nativeHdc = nativeHdc;
return _nativeHdc;
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
public void ReleaseHdc(IntPtr hdc)
{
ReleaseHdcInternal(hdc);
}
public void ReleaseHdc()
{
ReleaseHdcInternal(_nativeHdc);
}
public void Flush()
{
Flush(System.Drawing.Drawing2D.FlushIntention.Flush);
}
public unsafe void Flush(System.Drawing.Drawing2D.FlushIntention intention)
{
CheckStatus(PInvokeGdiPlus.GdipFlush(NativeGraphics, (global::Windows.Win32.Graphics.GdiPlus.FlushIntention)intention));
}
public void SetClip(Graphics g)
{
SetClip(g, System.Drawing.Drawing2D.CombineMode.Replace);
}
public unsafe void SetClip(Graphics g, System.Drawing.Drawing2D.CombineMode combineMode)
{
ArgumentNullException.ThrowIfNull(g, "g");
CheckStatus(PInvokeGdiPlus.GdipSetClipGraphics(NativeGraphics, g.NativeGraphics, (global::Windows.Win32.Graphics.GdiPlus.CombineMode)combineMode));
GC.KeepAlive(g);
}
public void SetClip(Rectangle rect)
{
SetClip(rect, System.Drawing.Drawing2D.CombineMode.Replace);
}
public void SetClip(Rectangle rect, System.Drawing.Drawing2D.CombineMode combineMode)
{
SetClip((RectangleF)rect, combineMode);
}
public void SetClip(RectangleF rect)
{
SetClip(rect, System.Drawing.Drawing2D.CombineMode.Replace);
}
public unsafe void SetClip(RectangleF rect, System.Drawing.Drawing2D.CombineMode combineMode)
{
CheckStatus(PInvokeGdiPlus.GdipSetClipRect(NativeGraphics, rect.X, rect.Y, rect.Width, rect.Height, (global::Windows.Win32.Graphics.GdiPlus.CombineMode)combineMode));
}
public void SetClip(GraphicsPath path)
{
SetClip(path, System.Drawing.Drawing2D.CombineMode.Replace);
}
public unsafe void SetClip(GraphicsPath path, System.Drawing.Drawing2D.CombineMode combineMode)
{
ArgumentNullException.ThrowIfNull(path, "path");
CheckStatus(PInvokeGdiPlus.GdipSetClipPath(NativeGraphics, path._nativePath, (global::Windows.Win32.Graphics.GdiPlus.CombineMode)combineMode));
GC.KeepAlive(path);
}
public unsafe void SetClip(Region region, System.Drawing.Drawing2D.CombineMode combineMode)
{
ArgumentNullException.ThrowIfNull(region, "region");
CheckStatus(PInvokeGdiPlus.GdipSetClipRegion(NativeGraphics, region.NativeRegion, (global::Windows.Win32.Graphics.GdiPlus.CombineMode)combineMode));
GC.KeepAlive(region);
}
public void IntersectClip(Rectangle rect)
{
IntersectClip((RectangleF)rect);
}
public unsafe void IntersectClip(RectangleF rect)
{
CheckStatus(PInvokeGdiPlus.GdipSetClipRect(NativeGraphics, rect.X, rect.Y, rect.Width, rect.Height, global::Windows.Win32.Graphics.GdiPlus.CombineMode.CombineModeIntersect));
}
public unsafe void IntersectClip(Region region)
{
ArgumentNullException.ThrowIfNull(region, "region");
CheckStatus(PInvokeGdiPlus.GdipSetClipRegion(NativeGraphics, region.NativeRegion, global::Windows.Win32.Graphics.GdiPlus.CombineMode.CombineModeIntersect));
GC.KeepAlive(region);
}
public unsafe void ExcludeClip(Rectangle rect)
{
CheckStatus(PInvokeGdiPlus.GdipSetClipRect(NativeGraphics, (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height, global::Windows.Win32.Graphics.GdiPlus.CombineMode.CombineModeExclude));
}
public unsafe void ExcludeClip(Region region)
{
ArgumentNullException.ThrowIfNull(region, "region");
CheckStatus(PInvokeGdiPlus.GdipSetClipRegion(NativeGraphics, region.NativeRegion, global::Windows.Win32.Graphics.GdiPlus.CombineMode.CombineModeExclude));
GC.KeepAlive(region);
}
public unsafe void ResetClip()
{
CheckStatus(PInvokeGdiPlus.GdipResetClip(NativeGraphics));
}
public unsafe void TranslateClip(float dx, float dy)
{
CheckStatus(PInvokeGdiPlus.GdipTranslateClip(NativeGraphics, dx, dy));
}
public unsafe void TranslateClip(int dx, int dy)
{
CheckStatus(PInvokeGdiPlus.GdipTranslateClip(NativeGraphics, (float)dx, (float)dy));
}
public bool IsVisible(int x, int y)
{
return IsVisible((float)x, (float)y);
}
public bool IsVisible(Point point)
{
return IsVisible(point.X, point.Y);
}
public unsafe bool IsVisible(float x, float y)
{
BOOL value = default(BOOL);
CheckStatus(PInvokeGdiPlus.GdipIsVisiblePoint(NativeGraphics, x, y, &value));
return value;
}
public bool IsVisible(PointF point)
{
return IsVisible(point.X, point.Y);
}
public bool IsVisible(int x, int y, int width, int height)
{
return IsVisible((float)x, (float)y, (float)width, (float)height);
}
public bool IsVisible(Rectangle rect)
{
return IsVisible((float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height);
}
public unsafe bool IsVisible(float x, float y, float width, float height)
{
BOOL value = default(BOOL);
CheckStatus(PInvokeGdiPlus.GdipIsVisibleRect(NativeGraphics, x, y, width, height, &value));
return value;
}
public bool IsVisible(RectangleF rect)
{
return IsVisible(rect.X, rect.Y, rect.Width, rect.Height);
}
public unsafe void ResetTransform()
{
CheckStatus(PInvokeGdiPlus.GdipResetWorldTransform(NativeGraphics));
}
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");
CheckStatus(PInvokeGdiPlus.GdipMultiplyWorldTransform(NativeGraphics, matrix.NativeMatrix, (global::Windows.Win32.Graphics.GdiPlus.MatrixOrder)order));
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)
{
CheckStatus(PInvokeGdiPlus.GdipTranslateWorldTransform(NativeGraphics, dx, dy, (global::Windows.Win32.Graphics.GdiPlus.MatrixOrder)order));
}
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)
{
CheckStatus(PInvokeGdiPlus.GdipScaleWorldTransform(NativeGraphics, sx, sy, (global::Windows.Win32.Graphics.GdiPlus.MatrixOrder)order));
}
public void RotateTransform(float angle)
{
RotateTransform(angle, System.Drawing.Drawing2D.MatrixOrder.Prepend);
}
public unsafe void RotateTransform(float angle, System.Drawing.Drawing2D.MatrixOrder order)
{
CheckStatus(PInvokeGdiPlus.GdipRotateWorldTransform(NativeGraphics, angle, (global::Windows.Win32.Graphics.GdiPlus.MatrixOrder)order));
}
public unsafe void DrawArc(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
CheckErrorStatus(PInvokeGdiPlus.GdipDrawArc(NativeGraphics, pen.NativePen, x, y, width, height, startAngle, sweepAngle));
GC.KeepAlive(pen);
}
public void DrawArc(Pen pen, RectangleF rect, float startAngle, float sweepAngle)
{
DrawArc(pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
}
public void DrawArc(Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
{
DrawArc(pen, (float)x, (float)y, (float)width, (float)height, (float)startAngle, (float)sweepAngle);
}
public void DrawArc(Pen pen, Rectangle rect, float startAngle, float sweepAngle)
{
DrawArc(pen, (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height, startAngle, sweepAngle);
}
public unsafe void DrawBezier(Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
CheckErrorStatus(PInvokeGdiPlus.GdipDrawBezier(NativeGraphics, pen.NativePen, x1, y1, x2, y2, x3, y3, x4, y4));
GC.KeepAlive(pen);
}
public void DrawBezier(Pen pen, PointF pt1, PointF pt2, PointF pt3, PointF pt4)
{
DrawBezier(pen, pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
}
public void DrawBezier(Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)
{
DrawBezier(pen, (float)pt1.X, (float)pt1.Y, (float)pt2.X, (float)pt2.Y, (float)pt3.X, (float)pt3.Y, (float)pt4.X, (float)pt4.Y);
}
public void DrawRectangle(Pen pen, RectangleF rect)
{
DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
}
public void DrawRectangle(Pen pen, Rectangle rect)
{
DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
}
public void DrawRoundedRectangle(Pen pen, Rectangle rect, Size radius)
{
DrawRoundedRectangle(pen, (RectangleF)rect, (SizeF)radius);
}
public void DrawRoundedRectangle(Pen pen, RectangleF rect, SizeF radius)
{
using (GraphicsPath graphicsPath = new GraphicsPath()) {
graphicsPath.AddRoundedRectangle(rect, radius);
DrawPath(pen, graphicsPath);
}
}
public unsafe void DrawRectangle(Pen pen, float x, float y, float width, float height)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
CheckErrorStatus(PInvokeGdiPlus.GdipDrawRectangle(NativeGraphics, pen.NativePen, x, y, width, height));
GC.KeepAlive(pen);
}
public void DrawRectangle(Pen pen, int x, int y, int width, int height)
{
DrawRectangle(pen, (float)x, (float)y, (float)width, (float)height);
}
public void DrawRectangles(Pen pen, params RectangleF[] rects)
{
DrawRectangles(pen, rects.OrThrowIfNull("rects").AsSpan());
}
[NullableContext(0)]
public unsafe void DrawRectangles([Nullable(1)] Pen pen, [ParamCollection] [ScopedRef] ReadOnlySpan<RectangleF> rects)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (RectangleF* rects2 = &rects.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawRectangles(NativeGraphics, pen.NativePen, (RectF*)rects2, rects.Length));
}
GC.KeepAlive(pen);
}
public void DrawRectangles(Pen pen, params Rectangle[] rects)
{
DrawRectangles(pen, rects.OrThrowIfNull("rects").AsSpan());
}
[NullableContext(0)]
public unsafe void DrawRectangles([Nullable(1)] Pen pen, [ParamCollection] [ScopedRef] ReadOnlySpan<Rectangle> rects)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (Rectangle* rects2 = &rects.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawRectanglesI(NativeGraphics, pen.NativePen, (Rect*)rects2, rects.Length));
}
GC.KeepAlive(pen);
}
public void DrawEllipse(Pen pen, RectangleF rect)
{
DrawEllipse(pen, rect.X, rect.Y, rect.Width, rect.Height);
}
public unsafe void DrawEllipse(Pen pen, float x, float y, float width, float height)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
CheckErrorStatus(PInvokeGdiPlus.GdipDrawEllipse(NativeGraphics, pen.NativePen, x, y, width, height));
GC.KeepAlive(pen);
}
public void DrawEllipse(Pen pen, Rectangle rect)
{
DrawEllipse(pen, (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height);
}
public void DrawEllipse(Pen pen, int x, int y, int width, int height)
{
DrawEllipse(pen, (float)x, (float)y, (float)width, (float)height);
}
public void DrawPie(Pen pen, RectangleF rect, float startAngle, float sweepAngle)
{
DrawPie(pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
}
public unsafe void DrawPie(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
CheckErrorStatus(PInvokeGdiPlus.GdipDrawPie(NativeGraphics, pen.NativePen, x, y, width, height, startAngle, sweepAngle));
GC.KeepAlive(pen);
}
public void DrawPie(Pen pen, Rectangle rect, float startAngle, float sweepAngle)
{
DrawPie(pen, (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height, startAngle, sweepAngle);
}
public void DrawPie(Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
{
DrawPie(pen, (float)x, (float)y, (float)width, (float)height, (float)startAngle, (float)sweepAngle);
}
public void DrawPolygon(Pen pen, params PointF[] points)
{
DrawPolygon(pen, points.OrThrowIfNull("points").AsSpan());
}
[NullableContext(0)]
public unsafe void DrawPolygon([Nullable(1)] Pen pen, [ParamCollection] [ScopedRef] ReadOnlySpan<PointF> points)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (PointF* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawPolygon(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points2, points.Length));
}
GC.KeepAlive(pen);
}
public void DrawPolygon(Pen pen, params Point[] points)
{
DrawPolygon(pen, points.OrThrowIfNull("points").AsSpan());
}
[NullableContext(0)]
public unsafe void DrawPolygon([Nullable(1)] Pen pen, [ParamCollection] [ScopedRef] ReadOnlySpan<Point> points)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (Point* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawPolygonI(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.Point*)points2, points.Length));
}
GC.KeepAlive(pen);
}
public unsafe void DrawPath(Pen pen, GraphicsPath path)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
ArgumentNullException.ThrowIfNull(path, "path");
CheckErrorStatus(PInvokeGdiPlus.GdipDrawPath(NativeGraphics, pen.NativePen, path._nativePath));
GC.KeepAlive(pen);
GC.KeepAlive(path);
}
public void DrawCurve(Pen pen, params PointF[] points)
{
DrawCurve(pen, points.OrThrowIfNull("points").AsSpan());
}
[NullableContext(0)]
public unsafe void DrawCurve([Nullable(1)] Pen pen, [ParamCollection] [ScopedRef] ReadOnlySpan<PointF> points)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (PointF* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawCurve(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points2, points.Length));
}
GC.KeepAlive(pen);
}
public void DrawCurve(Pen pen, PointF[] points, float tension)
{
DrawCurve(pen, points.OrThrowIfNull("points").AsSpan(), tension);
}
[NullableContext(0)]
public unsafe void DrawCurve([Nullable(1)] Pen pen, ReadOnlySpan<PointF> points, float tension)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (PointF* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawCurve2(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points2, points.Length, tension));
}
GC.KeepAlive(pen);
}
public void DrawCurve(Pen pen, PointF[] points, int offset, int numberOfSegments)
{
DrawCurve(pen, points, offset, numberOfSegments, 0.5);
}
[NullableContext(0)]
public void DrawCurve([Nullable(1)] Pen pen, ReadOnlySpan<PointF> points, int offset, int numberOfSegments)
{
DrawCurve(pen, points, offset, numberOfSegments, 0.5);
}
public void DrawCurve(Pen pen, PointF[] points, int offset, int numberOfSegments, float tension)
{
DrawCurve(pen, points.OrThrowIfNull("points").AsSpan(), offset, numberOfSegments, tension);
}
[NullableContext(0)]
public unsafe void DrawCurve([Nullable(1)] Pen pen, ReadOnlySpan<PointF> points, int offset, int numberOfSegments, float tension)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (PointF* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawCurve3(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points2, points.Length, offset, numberOfSegments, tension));
}
GC.KeepAlive(pen);
}
public void DrawCurve(Pen pen, params Point[] points)
{
DrawCurve(pen, points.OrThrowIfNull("points").AsSpan());
}
[NullableContext(0)]
public unsafe void DrawCurve([Nullable(1)] Pen pen, [ParamCollection] [ScopedRef] ReadOnlySpan<Point> points)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (Point* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawCurveI(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.Point*)points2, points.Length));
}
GC.KeepAlive(pen);
}
public void DrawCurve(Pen pen, Point[] points, float tension)
{
DrawCurve(pen, points.OrThrowIfNull("points").AsSpan(), tension);
}
[NullableContext(0)]
public unsafe void DrawCurve([Nullable(1)] Pen pen, ReadOnlySpan<Point> points, float tension)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (Point* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawCurve2I(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.Point*)points2, points.Length, tension));
}
GC.KeepAlive(pen);
}
public void DrawCurve(Pen pen, Point[] points, int offset, int numberOfSegments, float tension)
{
DrawCurve(pen, points.OrThrowIfNull("points").AsSpan(), offset, numberOfSegments, tension);
}
[NullableContext(0)]
public unsafe void DrawCurve([Nullable(1)] Pen pen, ReadOnlySpan<Point> points, int offset, int numberOfSegments, float tension)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (Point* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawCurve3I(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.Point*)points2, points.Length, offset, numberOfSegments, tension));
}
GC.KeepAlive(pen);
}
public void DrawClosedCurve(Pen pen, params PointF[] points)
{
DrawClosedCurve(pen, points.OrThrowIfNull("points").AsSpan());
}
[NullableContext(0)]
public unsafe void DrawClosedCurve([Nullable(1)] Pen pen, [ParamCollection] [ScopedRef] ReadOnlySpan<PointF> points)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (PointF* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawClosedCurve(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points2, points.Length));
}
GC.KeepAlive(pen);
}
public void DrawClosedCurve(Pen pen, PointF[] points, float tension, System.Drawing.Drawing2D.FillMode fillmode)
{
DrawClosedCurve(pen, points.OrThrowIfNull("points").AsSpan(), tension, fillmode);
}
[NullableContext(0)]
public unsafe void DrawClosedCurve([Nullable(1)] Pen pen, ReadOnlySpan<PointF> points, float tension, System.Drawing.Drawing2D.FillMode fillmode)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (PointF* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawClosedCurve2(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points2, points.Length, tension));
}
GC.KeepAlive(pen);
}
public void DrawClosedCurve(Pen pen, params Point[] points)
{
DrawClosedCurve(pen, points.OrThrowIfNull("points").AsSpan());
}
[NullableContext(0)]
public unsafe void DrawClosedCurve([Nullable(1)] Pen pen, [ParamCollection] [ScopedRef] ReadOnlySpan<Point> points)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (Point* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawClosedCurveI(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.Point*)points2, points.Length));
}
GC.KeepAlive(pen);
}
public void DrawClosedCurve(Pen pen, Point[] points, float tension, System.Drawing.Drawing2D.FillMode fillmode)
{
DrawClosedCurve(pen, points.OrThrowIfNull("points").AsSpan(), tension, fillmode);
}
[NullableContext(0)]
public unsafe void DrawClosedCurve([Nullable(1)] Pen pen, ReadOnlySpan<Point> points, float tension, System.Drawing.Drawing2D.FillMode fillmode)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (Point* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawClosedCurve2I(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.Point*)points2, points.Length, tension));
}
GC.KeepAlive(pen);
}
public unsafe void Clear(Color color)
{
CheckStatus(PInvokeGdiPlus.GdipGraphicsClear(NativeGraphics, (uint)color.ToArgb()));
}
public void FillRoundedRectangle(Brush brush, Rectangle rect, Size radius)
{
FillRoundedRectangle(brush, (RectangleF)rect, (SizeF)radius);
}
public void FillRoundedRectangle(Brush brush, RectangleF rect, SizeF radius)
{
using (GraphicsPath graphicsPath = new GraphicsPath()) {
graphicsPath.AddRoundedRectangle(rect, radius);
FillPath(brush, graphicsPath);
}
}
public void FillRectangle(Brush brush, RectangleF rect)
{
FillRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height);
}
public unsafe void FillRectangle(Brush brush, float x, float y, float width, float height)
{
ArgumentNullException.ThrowIfNull(brush, "brush");
CheckErrorStatus(PInvokeGdiPlus.GdipFillRectangle(NativeGraphics, brush.NativeBrush, x, y, width, height));
GC.KeepAlive(brush);
}
public void FillRectangle(Brush brush, Rectangle rect)
{
FillRectangle(brush, (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height);
}
public void FillRectangle(Brush brush, int x, int y, int width, int height)
{
FillRectangle(brush, (float)x, (float)y, (float)width, (float)height);
}
public void FillRectangles(Brush brush, params RectangleF[] rects)
{
ArgumentNullException.ThrowIfNull(rects, "rects");
FillRectangles(brush, rects.AsSpan());
}
[NullableContext(0)]
public unsafe void FillRectangles([Nullable(1)] Brush brush, [ParamCollection] [ScopedRef] ReadOnlySpan<RectangleF> rects)
{
ArgumentNullException.ThrowIfNull(brush, "brush");
fixed (RectangleF* rects2 = &rects.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipFillRectangles(NativeGraphics, brush.NativeBrush, (RectF*)rects2, rects.Length));
}
GC.KeepAlive(brush);
}
public void FillRectangles(Brush brush, params Rectangle[] rects)
{
FillRectangles(brush, rects.OrThrowIfNull("rects").AsSpan());
}
[NullableContext(0)]
public unsafe void FillRectangles([Nullable(1)] Brush brush, [ParamCollection] [ScopedRef] ReadOnlySpan<Rectangle> rects)
{
ArgumentNullException.ThrowIfNull(brush, "brush");
fixed (Rectangle* rects2 = &rects.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipFillRectanglesI(NativeGraphics, brush.NativeBrush, (Rect*)rects2, rects.Length));
}
GC.KeepAlive(brush);
}
public void FillPolygon(Brush brush, params PointF[] points)
{
FillPolygon(brush, points, System.Drawing.Drawing2D.FillMode.Alternate);
}
[NullableContext(0)]
public void FillPolygon([Nullable(1)] Brush brush, [ParamCollection] [ScopedRef] ReadOnlySpan<PointF> points)
{
FillPolygon(brush, points, System.Drawing.Drawing2D.FillMode.Alternate);
}
public void FillPolygon(Brush brush, PointF[] points, System.Drawing.Drawing2D.FillMode fillMode)
{
FillPolygon(brush, points.OrThrowIfNull("points").AsSpan(), fillMode);
}
[NullableContext(0)]
public unsafe void FillPolygon([Nullable(1)] Brush brush, ReadOnlySpan<PointF> points, System.Drawing.Drawing2D.FillMode fillMode)
{
ArgumentNullException.ThrowIfNull(brush, "brush");
fixed (PointF* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipFillPolygon(NativeGraphics, brush.NativeBrush, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points2, points.Length, (global::Windows.Win32.Graphics.GdiPlus.FillMode)fillMode));
}
GC.KeepAlive(brush);
}
public void FillPolygon(Brush brush, Point[] points)
{
FillPolygon(brush, points, System.Drawing.Drawing2D.FillMode.Alternate);
}
[NullableContext(0)]
public void FillPolygon([Nullable(1)] Brush brush, [ParamCollection] [ScopedRef] ReadOnlySpan<Point> points)
{
FillPolygon(brush, points, System.Drawing.Drawing2D.FillMode.Alternate);
}
public void FillPolygon(Brush brush, Point[] points, System.Drawing.Drawing2D.FillMode fillMode)
{
FillPolygon(brush, points.OrThrowIfNull("points").AsSpan(), fillMode);
}
[NullableContext(0)]
public unsafe void FillPolygon([Nullable(1)] Brush brush, ReadOnlySpan<Point> points, System.Drawing.Drawing2D.FillMode fillMode)
{
ArgumentNullException.ThrowIfNull(brush, "brush");
fixed (Point* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipFillPolygonI(NativeGraphics, brush.NativeBrush, (global::Windows.Win32.Graphics.GdiPlus.Point*)points2, points.Length, (global::Windows.Win32.Graphics.GdiPlus.FillMode)fillMode));
}
GC.KeepAlive(brush);
}
public void FillEllipse(Brush brush, RectangleF rect)
{
FillEllipse(brush, rect.X, rect.Y, rect.Width, rect.Height);
}
public unsafe void FillEllipse(Brush brush, float x, float y, float width, float height)
{
ArgumentNullException.ThrowIfNull(brush, "brush");
CheckErrorStatus(PInvokeGdiPlus.GdipFillEllipse(NativeGraphics, brush.NativeBrush, x, y, width, height));
GC.KeepAlive(brush);
}
public void FillEllipse(Brush brush, Rectangle rect)
{
FillEllipse(brush, (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height);
}
public void FillEllipse(Brush brush, int x, int y, int width, int height)
{
FillEllipse(brush, (float)x, (float)y, (float)width, (float)height);
}
public void FillPie(Brush brush, Rectangle rect, float startAngle, float sweepAngle)
{
FillPie(brush, (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height, startAngle, sweepAngle);
}
public void FillPie(Brush brush, RectangleF rect, float startAngle, float sweepAngle)
{
FillPie(brush, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
}
public unsafe void FillPie(Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle)
{
ArgumentNullException.ThrowIfNull(brush, "brush");
CheckErrorStatus(PInvokeGdiPlus.GdipFillPie(NativeGraphics, brush.NativeBrush, x, y, width, height, startAngle, sweepAngle));
GC.KeepAlive(brush);
}
public void FillPie(Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle)
{
FillPie(brush, (float)x, (float)y, (float)width, (float)height, (float)startAngle, (float)sweepAngle);
}
public void FillClosedCurve(Brush brush, params PointF[] points)
{
FillClosedCurve(brush, points.OrThrowIfNull("points").AsSpan());
}
[NullableContext(0)]
public unsafe void FillClosedCurve([Nullable(1)] Brush brush, [ParamCollection] [ScopedRef] ReadOnlySpan<PointF> points)
{
ArgumentNullException.ThrowIfNull(brush, "brush");
fixed (PointF* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipFillClosedCurve(NativeGraphics, brush.NativeBrush, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points2, points.Length));
}
GC.KeepAlive(brush);
}
public void FillClosedCurve(Brush brush, PointF[] points, System.Drawing.Drawing2D.FillMode fillmode)
{
FillClosedCurve(brush, points, fillmode, 0.5);
}
[NullableContext(0)]
public void FillClosedCurve([Nullable(1)] Brush brush, ReadOnlySpan<PointF> points, System.Drawing.Drawing2D.FillMode fillmode)
{
FillClosedCurve(brush, points, fillmode, 0.5);
}
public void FillClosedCurve(Brush brush, PointF[] points, System.Drawing.Drawing2D.FillMode fillmode, float tension)
{
FillClosedCurve(brush, points.OrThrowIfNull("points").AsSpan(), fillmode, tension);
}
[NullableContext(0)]
public unsafe void FillClosedCurve([Nullable(1)] Brush brush, ReadOnlySpan<PointF> points, System.Drawing.Drawing2D.FillMode fillmode, float tension)
{
ArgumentNullException.ThrowIfNull(brush, "brush");
fixed (PointF* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipFillClosedCurve2(NativeGraphics, brush.NativeBrush, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points2, points.Length, tension, (global::Windows.Win32.Graphics.GdiPlus.FillMode)fillmode));
}
GC.KeepAlive(brush);
}
public void FillClosedCurve(Brush brush, params Point[] points)
{
FillClosedCurve(brush, points.OrThrowIfNull("points").AsSpan());
}
[NullableContext(0)]
public unsafe void FillClosedCurve([Nullable(1)] Brush brush, [ParamCollection] [ScopedRef] ReadOnlySpan<Point> points)
{
ArgumentNullException.ThrowIfNull(brush, "brush");
fixed (Point* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipFillClosedCurveI(NativeGraphics, brush.NativeBrush, (global::Windows.Win32.Graphics.GdiPlus.Point*)points2, points.Length));
}
GC.KeepAlive(brush);
}
public void FillClosedCurve(Brush brush, Point[] points, System.Drawing.Drawing2D.FillMode fillmode)
{
FillClosedCurve(brush, points, fillmode, 0.5);
}
[NullableContext(0)]
public void FillClosedCurve([Nullable(1)] Brush brush, ReadOnlySpan<Point> points, System.Drawing.Drawing2D.FillMode fillmode)
{
FillClosedCurve(brush, points, fillmode, 0.5);
}
public void FillClosedCurve(Brush brush, Point[] points, System.Drawing.Drawing2D.FillMode fillmode, float tension)
{
FillClosedCurve(brush, points.OrThrowIfNull("points").AsSpan(), fillmode, tension);
}
[NullableContext(0)]
public unsafe void FillClosedCurve([Nullable(1)] Brush brush, ReadOnlySpan<Point> points, System.Drawing.Drawing2D.FillMode fillmode, float tension)
{
ArgumentNullException.ThrowIfNull(brush, "brush");
fixed (Point* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipFillClosedCurve2I(NativeGraphics, brush.NativeBrush, (global::Windows.Win32.Graphics.GdiPlus.Point*)points2, points.Length, tension, (global::Windows.Win32.Graphics.GdiPlus.FillMode)fillmode));
}
GC.KeepAlive(brush);
}
public void DrawString([Nullable(2)] string s, Font font, Brush brush, float x, float y)
{
DrawString(s, font, brush, new RectangleF(x, y, 0, 0), null);
}
public void DrawString([Nullable(0)] ReadOnlySpan<char> s, Font font, Brush brush, float x, float y)
{
DrawString(s, font, brush, new RectangleF(x, y, 0, 0), null);
}
public void DrawString([Nullable(2)] string s, Font font, Brush brush, PointF point)
{
DrawString(s, font, brush, new RectangleF(point.X, point.Y, 0, 0), null);
}
public void DrawString([Nullable(0)] ReadOnlySpan<char> s, Font font, Brush brush, PointF point)
{
DrawString(s, font, brush, new RectangleF(point.X, point.Y, 0, 0), null);
}
public void DrawString([Nullable(2)] string s, Font font, Brush brush, float x, float y, [Nullable(2)] StringFormat format)
{
DrawString(s, font, brush, new RectangleF(x, y, 0, 0), format);
}
public void DrawString([Nullable(0)] ReadOnlySpan<char> s, Font font, Brush brush, float x, float y, [Nullable(2)] StringFormat format)
{
DrawString(s, font, brush, new RectangleF(x, y, 0, 0), format);
}
public void DrawString([Nullable(2)] string s, Font font, Brush brush, PointF point, [Nullable(2)] StringFormat format)
{
DrawString(s, font, brush, new RectangleF(point.X, point.Y, 0, 0), format);
}
public void DrawString([Nullable(0)] ReadOnlySpan<char> s, Font font, Brush brush, PointF point, [Nullable(2)] StringFormat format)
{
DrawString(s, font, brush, new RectangleF(point.X, point.Y, 0, 0), format);
}
public void DrawString([Nullable(2)] string s, Font font, Brush brush, RectangleF layoutRectangle)
{
DrawString(s, font, brush, layoutRectangle, null);
}
public void DrawString([Nullable(0)] ReadOnlySpan<char> s, Font font, Brush brush, RectangleF layoutRectangle)
{
DrawString(s, font, brush, layoutRectangle, null);
}
public void DrawString([Nullable(2)] string s, Font font, Brush brush, RectangleF layoutRectangle, [Nullable(2)] StringFormat format)
{
DrawStringInternal(s.AsSpan(), font, brush, layoutRectangle, format);
}
public void DrawString([Nullable(0)] ReadOnlySpan<char> s, Font font, Brush brush, RectangleF layoutRectangle, [Nullable(2)] StringFormat format)
{
DrawStringInternal(s, font, brush, layoutRectangle, format);
}
private unsafe void DrawStringInternal([Nullable(0)] ReadOnlySpan<char> s, Font font, Brush brush, RectangleF layoutRectangle, [Nullable(2)] StringFormat format)
{
ArgumentNullException.ThrowIfNull(brush, "brush");
if (!s.IsEmpty) {
ArgumentNullException.ThrowIfNull(font, "font");
fixed (char* value = &s.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawString(NativeGraphics, value, s.Length, font.NativeFont, (RectF*)(&layoutRectangle), format.Pointer(), brush.NativeBrush));
}
GC.KeepAlive(font);
GC.KeepAlive(brush);
GC.KeepAlive(format);
}
}
[NullableContext(2)]
public SizeF MeasureString(string text, [Nullable(1)] Font font, SizeF layoutArea, StringFormat stringFormat, out int charactersFitted, out int linesFilled)
{
return MeasureStringInternal(text.AsSpan(), font, new RectangleF(default(PointF), layoutArea), stringFormat, out charactersFitted, out linesFilled);
}
[NullableContext(0)]
public SizeF MeasureString(ReadOnlySpan<char> text, [Nullable(1)] Font font, SizeF layoutArea, [Nullable(2)] StringFormat stringFormat, out int charactersFitted, out int linesFilled)
{
return MeasureStringInternal(text, font, new RectangleF(default(PointF), layoutArea), stringFormat, out charactersFitted, out linesFilled);
}
[NullableContext(0)]
public unsafe SizeF MeasureStringInternal(ReadOnlySpan<char> text, [Nullable(1)] Font font, RectangleF layoutArea, [Nullable(2)] StringFormat stringFormat, out int charactersFitted, out int linesFilled)
{
if (text.IsEmpty) {
charactersFitted = 0;
linesFilled = 0;
return SizeF.Empty;
}
ArgumentNullException.ThrowIfNull(font, "font");
RectF rectF = default(RectF);
fixed (char* value = &text.GetPinnableReference()) {
fixed (int* codepointsFitted = &charactersFitted) {
fixed (int* linesFilled2 = &linesFilled) {
CheckStatus(PInvokeGdiPlus.GdipMeasureString(NativeGraphics, value, text.Length, font.NativeFont, (RectF*)(&layoutArea), stringFormat.Pointer(), &rectF, codepointsFitted, linesFilled2));
}
}
}
GC.KeepAlive(font);
GC.KeepAlive(stringFormat);
return new SizeF(rectF.Width, rectF.Height);
}
[NullableContext(2)]
public SizeF MeasureString(string text, [Nullable(1)] Font font, PointF origin, StringFormat stringFormat)
{
int charactersFitted;
int linesFilled;
return MeasureStringInternal(text.AsSpan(), font, new RectangleF(origin, default(SizeF)), stringFormat, out charactersFitted, out linesFilled);
}
[NullableContext(0)]
public SizeF MeasureString(ReadOnlySpan<char> text, [Nullable(1)] Font font, PointF origin, [Nullable(2)] StringFormat stringFormat)
{
int charactersFitted;
int linesFilled;
return MeasureStringInternal(text, font, new RectangleF(origin, default(SizeF)), stringFormat, out charactersFitted, out linesFilled);
}
public SizeF MeasureString([Nullable(2)] string text, Font font, SizeF layoutArea)
{
return MeasureString(text, font, layoutArea, null);
}
[NullableContext(0)]
public SizeF MeasureString(ReadOnlySpan<char> text, [Nullable(1)] Font font, SizeF layoutArea)
{
return MeasureString(text, font, layoutArea, null);
}
[NullableContext(2)]
public SizeF MeasureString(string text, [Nullable(1)] Font font, SizeF layoutArea, StringFormat stringFormat)
{
int charactersFitted;
int linesFilled;
return MeasureStringInternal(text.AsSpan(), font, new RectangleF(default(PointF), layoutArea), stringFormat, out charactersFitted, out linesFilled);
}
[NullableContext(0)]
public SizeF MeasureString(ReadOnlySpan<char> text, [Nullable(1)] Font font, SizeF layoutArea, [Nullable(2)] StringFormat stringFormat)
{
int charactersFitted;
int linesFilled;
return MeasureStringInternal(text, font, new RectangleF(default(PointF), layoutArea), stringFormat, out charactersFitted, out linesFilled);
}
public SizeF MeasureString([Nullable(2)] string text, Font font)
{
return MeasureString(text, font, new SizeF(0, 0));
}
[NullableContext(0)]
public SizeF MeasureString(ReadOnlySpan<char> text, [Nullable(1)] Font font)
{
return MeasureString(text, font, new SizeF(0, 0));
}
public SizeF MeasureString([Nullable(2)] string text, Font font, int width)
{
return MeasureString(text, font, new SizeF((float)width, 999999));
}
[NullableContext(0)]
public SizeF MeasureString(ReadOnlySpan<char> text, [Nullable(1)] Font font, int width)
{
return MeasureString(text, font, new SizeF((float)width, 999999));
}
[NullableContext(2)]
public SizeF MeasureString(string text, [Nullable(1)] Font font, int width, StringFormat format)
{
return MeasureString(text, font, new SizeF((float)width, 999999), format);
}
[NullableContext(0)]
public SizeF MeasureString(ReadOnlySpan<char> text, [Nullable(1)] Font font, int width, [Nullable(2)] StringFormat format)
{
return MeasureString(text, font, new SizeF((float)width, 999999), format);
}
public Region[] MeasureCharacterRanges([Nullable(2)] string text, Font font, RectangleF layoutRect, [Nullable(2)] StringFormat stringFormat)
{
return MeasureCharacterRangesInternal(text.AsSpan(), font, layoutRect, stringFormat);
}
public Region[] MeasureCharacterRanges([Nullable(0)] ReadOnlySpan<char> text, Font font, RectangleF layoutRect, [Nullable(2)] StringFormat stringFormat)
{
return MeasureCharacterRangesInternal(text, font, layoutRect, stringFormat);
}
private unsafe Region[] MeasureCharacterRangesInternal([Nullable(0)] ReadOnlySpan<char> text, Font font, RectF layoutRect, [Nullable(2)] StringFormat stringFormat)
{
if (text.IsEmpty)
return Array.Empty<Region>();
ArgumentNullException.ThrowIfNull(font, "font");
int num = default(int);
CheckStatus(PInvokeGdiPlus.GdipGetStringFormatMeasurableCharacterRangeCount(stringFormat.Pointer(), &num));
if (num == 0)
return Array.Empty<Region>();
GpRegion*[] array = new GpRegion*[num];
Region[] array2 = new Region[num];
for (int i = 0; i < num; i++) {
array2[i] = new Region();
array[i] = array2[i].NativeRegion;
}
fixed (char* value = &text.GetPinnableReference()) {
fixed (GpRegion** regions = array) {
CheckStatus(PInvokeGdiPlus.GdipMeasureCharacterRanges(NativeGraphics, value, text.Length, font.NativeFont, &layoutRect, stringFormat.Pointer(), num, regions));
}
}
GC.KeepAlive(stringFormat);
GC.KeepAlive(font);
return array2;
}
public void DrawImage(Image image, PointF point)
{
DrawImage(image, point.X, point.Y);
}
public unsafe void DrawImage(Image image, float x, float y)
{
ArgumentNullException.ThrowIfNull(image, "image");
Status errorStatus = PInvokeGdiPlus.GdipDrawImage(NativeGraphics, image.Pointer(), x, y);
IgnoreMetafileErrors(image, ref errorStatus);
CheckErrorStatus(errorStatus);
}
public void DrawImage(Image image, RectangleF rect)
{
DrawImage(image, rect.X, rect.Y, rect.Width, rect.Height);
}
public unsafe void DrawImage(Image image, float x, float y, float width, float height)
{
ArgumentNullException.ThrowIfNull(image, "image");
Status errorStatus = PInvokeGdiPlus.GdipDrawImageRect(NativeGraphics, image.Pointer(), x, y, width, height);
IgnoreMetafileErrors(image, ref errorStatus);
CheckErrorStatus(errorStatus);
}
public void DrawImage(Image image, Point point)
{
DrawImage(image, (float)point.X, (float)point.Y);
}
public void DrawImage(Image image, int x, int y)
{
DrawImage(image, (float)x, (float)y);
}
public void DrawImage(Image image, Rectangle rect)
{
DrawImage(image, (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height);
}
public void DrawImage(Image image, int x, int y, int width, int height)
{
DrawImage(image, (float)x, (float)y, (float)width, (float)height);
}
public void DrawImageUnscaled(Image image, Point point)
{
DrawImage(image, point.X, point.Y);
}
public void DrawImageUnscaled(Image image, int x, int y)
{
DrawImage(image, x, y);
}
public void DrawImageUnscaled(Image image, Rectangle rect)
{
DrawImage(image, rect.X, rect.Y);
}
public void DrawImageUnscaled(Image image, int x, int y, int width, int height)
{
DrawImage(image, x, y);
}
public void DrawImageUnscaledAndClipped(Image image, Rectangle rect)
{
ArgumentNullException.ThrowIfNull(image, "image");
int srcWidth = Math.Min(rect.Width, image.Width);
int srcHeight = Math.Min(rect.Height, image.Height);
DrawImage(image, rect, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel);
}
public unsafe void DrawImage(Image image, PointF[] destPoints)
{
ArgumentNullException.ThrowIfNull(image, "image");
ArgumentNullException.ThrowIfNull(destPoints, "destPoints");
int num = destPoints.Length;
if (num != 3 && num != 4)
throw new ArgumentException(System.SR.GdiplusDestPointsInvalidLength);
fixed (PointF* dstpoints = destPoints) {
Status errorStatus = PInvokeGdiPlus.GdipDrawImagePoints(NativeGraphics, image.Pointer(), (global::Windows.Win32.Graphics.GdiPlus.PointF*)dstpoints, num);
IgnoreMetafileErrors(image, ref errorStatus);
CheckErrorStatus(errorStatus);
}
}
public unsafe void DrawImage(Image image, Point[] destPoints)
{
ArgumentNullException.ThrowIfNull(image, "image");
ArgumentNullException.ThrowIfNull(destPoints, "destPoints");
int num = destPoints.Length;
if (num != 3 && num != 4)
throw new ArgumentException(System.SR.GdiplusDestPointsInvalidLength);
fixed (Point* dstpoints = destPoints) {
Status errorStatus = PInvokeGdiPlus.GdipDrawImagePointsI(NativeGraphics, image.Pointer(), (global::Windows.Win32.Graphics.GdiPlus.Point*)dstpoints, num);
IgnoreMetafileErrors(image, ref errorStatus);
CheckErrorStatus(errorStatus);
}
}
public unsafe void DrawImage(Image image, float x, float y, RectangleF srcRect, GraphicsUnit srcUnit)
{
ArgumentNullException.ThrowIfNull(image, "image");
Status errorStatus = PInvokeGdiPlus.GdipDrawImagePointRect(NativeGraphics, image.Pointer(), x, y, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, (Unit)srcUnit);
IgnoreMetafileErrors(image, ref errorStatus);
CheckErrorStatus(errorStatus);
}
public void DrawImage(Image image, int x, int y, Rectangle srcRect, GraphicsUnit srcUnit)
{
DrawImage(image, (float)x, (float)y, srcRect, srcUnit);
}
public unsafe void DrawImage(Image image, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit)
{
ArgumentNullException.ThrowIfNull(image, "image");
Status errorStatus = PInvokeGdiPlus.GdipDrawImageRectRect(NativeGraphics, image.Pointer(), destRect.X, destRect.Y, destRect.Width, destRect.Height, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, (Unit)srcUnit, null, (IntPtr)0, null);
IgnoreMetafileErrors(image, ref errorStatus);
CheckErrorStatus(errorStatus);
}
public void DrawImage(Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit)
{
DrawImage(image, destRect, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, srcUnit);
}
public unsafe void DrawImage(Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit)
{
ArgumentNullException.ThrowIfNull(image, "image");
ArgumentNullException.ThrowIfNull(destPoints, "destPoints");
int num = destPoints.Length;
if (num != 3 && num != 4)
throw new ArgumentException(System.SR.GdiplusDestPointsInvalidLength);
fixed (PointF* points = destPoints) {
Status errorStatus = PInvokeGdiPlus.GdipDrawImagePointsRect(NativeGraphics, image.Pointer(), (global::Windows.Win32.Graphics.GdiPlus.PointF*)points, destPoints.Length, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, (Unit)srcUnit, null, (IntPtr)0, null);
IgnoreMetafileErrors(image, ref errorStatus);
CheckErrorStatus(errorStatus);
}
}
public void DrawImage(Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, [Nullable(2)] ImageAttributes imageAttr)
{
DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, null, 0);
}
public void DrawImage(Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, [Nullable(2)] ImageAttributes imageAttr, [Nullable(2)] DrawImageAbort callback)
{
DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, callback, 0);
}
public unsafe void DrawImage(Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, [Nullable(2)] ImageAttributes imageAttr, [Nullable(2)] DrawImageAbort callback, int callbackData)
{
ArgumentNullException.ThrowIfNull(image, "image");
ArgumentNullException.ThrowIfNull(destPoints, "destPoints");
int num = destPoints.Length;
if (num != 3 && num != 4)
throw new ArgumentException(System.SR.GdiplusDestPointsInvalidLength);
fixed (PointF* points = destPoints) {
Status errorStatus = PInvokeGdiPlus.GdipDrawImagePointsRect(NativeGraphics, image.Pointer(), (global::Windows.Win32.Graphics.GdiPlus.PointF*)points, destPoints.Length, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, (Unit)srcUnit, imageAttr.Pointer(), (callback == null) ? ((IntPtr)0) : Marshal.GetFunctionPointerForDelegate(callback), (void*)callbackData);
GC.KeepAlive(imageAttr);
GC.KeepAlive(callback);
IgnoreMetafileErrors(image, ref errorStatus);
CheckErrorStatus(errorStatus);
}
}
public void DrawImage(Image image, Point[] destPoints, Rectangle srcRect, GraphicsUnit srcUnit)
{
DrawImage(image, destPoints, srcRect, srcUnit, null, null, 0);
}
public void DrawImage(Image image, Point[] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, [Nullable(2)] ImageAttributes imageAttr)
{
DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, null, 0);
}
public void DrawImage(Image image, Point[] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, [Nullable(2)] ImageAttributes imageAttr, [Nullable(2)] DrawImageAbort callback)
{
DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, callback, 0);
}
public unsafe void DrawImage(Image image, Point[] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, [Nullable(2)] ImageAttributes imageAttr, [Nullable(2)] DrawImageAbort callback, int callbackData)
{
ArgumentNullException.ThrowIfNull(image, "image");
ArgumentNullException.ThrowIfNull(destPoints, "destPoints");
int num = destPoints.Length;
if (num != 3 && num != 4)
throw new ArgumentException(System.SR.GdiplusDestPointsInvalidLength);
fixed (Point* points = destPoints) {
Status errorStatus = PInvokeGdiPlus.GdipDrawImagePointsRectI(NativeGraphics, image.Pointer(), (global::Windows.Win32.Graphics.GdiPlus.Point*)points, destPoints.Length, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, (Unit)srcUnit, imageAttr.Pointer(), (callback == null) ? ((IntPtr)0) : Marshal.GetFunctionPointerForDelegate(callback), (void*)callbackData);
GC.KeepAlive(imageAttr);
GC.KeepAlive(callback);
IgnoreMetafileErrors(image, ref errorStatus);
CheckErrorStatus(errorStatus);
}
}
public void DrawImage(Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit)
{
DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, null);
}
public void DrawImage(Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, [Nullable(2)] ImageAttributes imageAttrs)
{
DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttrs, null);
}
[NullableContext(2)]
public void DrawImage([Nullable(1)] Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback)
{
DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttrs, callback, IntPtr.Zero);
}
[NullableContext(2)]
public unsafe void DrawImage([Nullable(1)] Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData)
{
ArgumentNullException.ThrowIfNull(image, "image");
Status errorStatus = PInvokeGdiPlus.GdipDrawImageRectRect(NativeGraphics, image.Pointer(), (float)destRect.X, (float)destRect.Y, (float)destRect.Width, (float)destRect.Height, srcX, srcY, srcWidth, srcHeight, (Unit)srcUnit, imageAttrs.Pointer(), (callback == null) ? ((IntPtr)0) : Marshal.GetFunctionPointerForDelegate(callback), (void*)(long)callbackData);
GC.KeepAlive(imageAttrs);
GC.KeepAlive(callback);
IgnoreMetafileErrors(image, ref errorStatus);
CheckErrorStatus(errorStatus);
}
public void DrawImage(Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit)
{
DrawImage(image, destRect, (float)srcX, (float)srcY, (float)srcWidth, (float)srcHeight, srcUnit, null);
}
public void DrawImage(Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, [Nullable(2)] ImageAttributes imageAttr)
{
DrawImage(image, destRect, (float)srcX, (float)srcY, (float)srcWidth, (float)srcHeight, srcUnit, imageAttr, null);
}
[NullableContext(2)]
public void DrawImage([Nullable(1)] Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
{
DrawImage(image, destRect, (float)srcX, (float)srcY, (float)srcWidth, (float)srcHeight, srcUnit, imageAttr, callback, IntPtr.Zero);
}
[NullableContext(2)]
public void DrawImage([Nullable(1)] Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData)
{
DrawImage(image, destRect, (float)srcX, (float)srcY, (float)srcWidth, (float)srcHeight, srcUnit, imageAttrs, callback, callbackData);
}
public void DrawLine(Pen pen, PointF pt1, PointF pt2)
{
DrawLine(pen, pt1.X, pt1.Y, pt2.X, pt2.Y);
}
public void DrawLines(Pen pen, params PointF[] points)
{
DrawLines(pen, points.OrThrowIfNull("points").AsSpan());
}
[NullableContext(0)]
public unsafe void DrawLines([Nullable(1)] Pen pen, [ParamCollection] [ScopedRef] ReadOnlySpan<PointF> points)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (PointF* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawLines(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points2, points.Length));
}
GC.KeepAlive(pen);
}
public void DrawLine(Pen pen, int x1, int y1, int x2, int y2)
{
DrawLine(pen, (float)x1, (float)y1, (float)x2, (float)y2);
}
public void DrawLine(Pen pen, Point pt1, Point pt2)
{
DrawLine(pen, (float)pt1.X, (float)pt1.Y, (float)pt2.X, (float)pt2.Y);
}
public unsafe void DrawLines(Pen pen, params Point[] points)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
ArgumentNullException.ThrowIfNull(points, "points");
fixed (Point* points2 = points) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawLinesI(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.Point*)points2, points.Length));
}
GC.KeepAlive(pen);
}
[NullableContext(0)]
public unsafe void DrawLines([Nullable(1)] Pen pen, [ParamCollection] [ScopedRef] ReadOnlySpan<Point> points)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (Point* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawLinesI(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.Point*)points2, points.Length));
}
GC.KeepAlive(pen);
}
public void CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize)
{
CopyFromScreen(upperLeftSource.X, upperLeftSource.Y, upperLeftDestination.X, upperLeftDestination.Y, blockRegionSize);
}
public void CopyFromScreen(int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize)
{
CopyFromScreen(sourceX, sourceY, destinationX, destinationY, blockRegionSize, CopyPixelOperation.SourceCopy);
}
public void CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
{
CopyFromScreen(upperLeftSource.X, upperLeftSource.Y, upperLeftDestination.X, upperLeftDestination.Y, blockRegionSize, copyPixelOperation);
}
public void EnumerateMetafile(Metafile metafile, PointF destPoint, EnumerateMetafileProc callback)
{
EnumerateMetafile(metafile, destPoint, callback, IntPtr.Zero);
}
public void EnumerateMetafile(Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
{
EnumerateMetafile(metafile, destPoint, callback, callbackData, null);
}
public void EnumerateMetafile(Metafile metafile, Point destPoint, EnumerateMetafileProc callback)
{
EnumerateMetafile(metafile, destPoint, callback, IntPtr.Zero);
}
public void EnumerateMetafile(Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
{
EnumerateMetafile(metafile, destPoint, callback, callbackData, null);
}
public void EnumerateMetafile(Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback)
{
EnumerateMetafile(metafile, destRect, callback, IntPtr.Zero);
}
public void EnumerateMetafile(Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData)
{
EnumerateMetafile(metafile, destRect, callback, callbackData, null);
}
public void EnumerateMetafile(Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback)
{
EnumerateMetafile(metafile, destRect, callback, IntPtr.Zero);
}
public void EnumerateMetafile(Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData)
{
EnumerateMetafile(metafile, destRect, callback, callbackData, null);
}
public void EnumerateMetafile(Metafile metafile, PointF[] destPoints, EnumerateMetafileProc callback)
{
EnumerateMetafile(metafile, destPoints, callback, IntPtr.Zero);
}
public void EnumerateMetafile(Metafile metafile, PointF[] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
{
EnumerateMetafile(metafile, destPoints, callback, IntPtr.Zero, null);
}
public void EnumerateMetafile(Metafile metafile, Point[] destPoints, EnumerateMetafileProc callback)
{
EnumerateMetafile(metafile, destPoints, callback, IntPtr.Zero);
}
public void EnumerateMetafile(Metafile metafile, Point[] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
{
EnumerateMetafile(metafile, destPoints, callback, callbackData, null);
}
public void EnumerateMetafile(Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
{
EnumerateMetafile(metafile, destPoint, srcRect, srcUnit, callback, IntPtr.Zero);
}
public void EnumerateMetafile(Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
{
EnumerateMetafile(metafile, destPoint, srcRect, srcUnit, callback, callbackData, null);
}
public void EnumerateMetafile(Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
{
EnumerateMetafile(metafile, destPoint, srcRect, srcUnit, callback, IntPtr.Zero);
}
public void EnumerateMetafile(Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
{
EnumerateMetafile(metafile, destPoint, srcRect, srcUnit, callback, callbackData, null);
}
public void EnumerateMetafile(Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
{
EnumerateMetafile(metafile, destRect, srcRect, srcUnit, callback, IntPtr.Zero);
}
public void EnumerateMetafile(Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
{
EnumerateMetafile(metafile, destRect, srcRect, srcUnit, callback, callbackData, null);
}
public void EnumerateMetafile(Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
{
EnumerateMetafile(metafile, destRect, srcRect, srcUnit, callback, IntPtr.Zero);
}
public void EnumerateMetafile(Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
{
EnumerateMetafile(metafile, destRect, srcRect, srcUnit, callback, callbackData, null);
}
public void EnumerateMetafile(Metafile metafile, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
{
EnumerateMetafile(metafile, destPoints, srcRect, srcUnit, callback, IntPtr.Zero);
}
public void EnumerateMetafile(Metafile metafile, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
{
EnumerateMetafile(metafile, destPoints, srcRect, srcUnit, callback, callbackData, null);
}
public void EnumerateMetafile(Metafile metafile, Point[] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
{
EnumerateMetafile(metafile, destPoints, srcRect, srcUnit, callback, IntPtr.Zero);
}
public void EnumerateMetafile(Metafile metafile, Point[] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
{
EnumerateMetafile(metafile, destPoints, srcRect, srcUnit, callback, callbackData, null);
}
public void TransformPoints(System.Drawing.Drawing2D.CoordinateSpace destSpace, System.Drawing.Drawing2D.CoordinateSpace srcSpace, params PointF[] pts)
{
ArgumentNullException.ThrowIfNull(pts, "pts");
TransformPoints(destSpace, srcSpace, pts.AsSpan());
}
[NullableContext(0)]
public unsafe void TransformPoints(System.Drawing.Drawing2D.CoordinateSpace destSpace, System.Drawing.Drawing2D.CoordinateSpace srcSpace, [ParamCollection] [ScopedRef] ReadOnlySpan<PointF> pts)
{
fixed (PointF* points = &pts.GetPinnableReference()) {
CheckStatus(PInvokeGdiPlus.GdipTransformPoints(NativeGraphics, (global::Windows.Win32.Graphics.GdiPlus.CoordinateSpace)destSpace, (global::Windows.Win32.Graphics.GdiPlus.CoordinateSpace)srcSpace, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points, pts.Length));
}
}
public void TransformPoints(System.Drawing.Drawing2D.CoordinateSpace destSpace, System.Drawing.Drawing2D.CoordinateSpace srcSpace, params Point[] pts)
{
ArgumentNullException.ThrowIfNull(pts, "pts");
TransformPoints(destSpace, srcSpace, pts.AsSpan());
}
[NullableContext(0)]
public unsafe void TransformPoints(System.Drawing.Drawing2D.CoordinateSpace destSpace, System.Drawing.Drawing2D.CoordinateSpace srcSpace, [ParamCollection] [ScopedRef] ReadOnlySpan<Point> pts)
{
fixed (Point* points = &pts.GetPinnableReference()) {
CheckStatus(PInvokeGdiPlus.GdipTransformPointsI(NativeGraphics, (global::Windows.Win32.Graphics.GdiPlus.CoordinateSpace)destSpace, (global::Windows.Win32.Graphics.GdiPlus.CoordinateSpace)srcSpace, (global::Windows.Win32.Graphics.GdiPlus.Point*)points, pts.Length));
}
}
private static void IgnoreMetafileErrors(Image image, ref Status errorStatus)
{
if (errorStatus != 0 && image.RawFormat.Equals(ImageFormat.Emf))
errorStatus = Status.Ok;
GC.KeepAlive(image);
}
[NullableContext(2)]
internal unsafe Region GetRegionIfNotInfinite()
{
GpRegion* ptr = default(GpRegion*);
CheckStatus(PInvokeGdiPlus.GdipCreateRegion(&ptr));
try {
PInvokeGdiPlus.GdipGetClip(NativeGraphics, ptr);
BOOL value = default(BOOL);
CheckStatus(PInvokeGdiPlus.GdipIsInfiniteRegion(ptr, NativeGraphics, &value));
if (!(bool)value) {
Region result = new Region(ptr);
ptr = null;
return result;
}
return null;
} finally {
if (ptr != null)
PInvokeGdiPlus.GdipDeleteRegion(ptr);
}
}
public void CopyFromScreen(int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
{
switch (copyPixelOperation) {
default:
throw new InvalidEnumArgumentException("copyPixelOperation", (int)copyPixelOperation, typeof(CopyPixelOperation));
case CopyPixelOperation.NoMirrorBitmap:
case CopyPixelOperation.Blackness:
case CopyPixelOperation.NotSourceErase:
case CopyPixelOperation.NotSourceCopy:
case CopyPixelOperation.SourceErase:
case CopyPixelOperation.DestinationInvert:
case CopyPixelOperation.PatInvert:
case CopyPixelOperation.SourceInvert:
case CopyPixelOperation.SourceAnd:
case CopyPixelOperation.MergePaint:
case CopyPixelOperation.MergeCopy:
case CopyPixelOperation.SourceCopy:
case CopyPixelOperation.SourcePaint:
case CopyPixelOperation.PatCopy:
case CopyPixelOperation.PatPaint:
case CopyPixelOperation.Whiteness:
case CopyPixelOperation.CaptureBlt: {
int width = blockRegionSize.Width;
int height = blockRegionSize.Height;
GetDcScope scope = GetDcScope.ScreenDC;
try {
if ((long)(IntPtr)ref scope == 0)
throw new Win32Exception(6);
HDC hdc = (HDC)GetHdc();
try {
if (!(bool)PInvokeCore.BitBlt(hdc, destinationX, destinationY, width, height, (HDC)ref scope, sourceX, sourceY, (ROP_CODE)copyPixelOperation))
throw new Win32Exception();
} finally {
if (!hdc.IsNull)
ReleaseHdc();
}
} finally {
scope.Dispose();
}
break;
}
}
}
public unsafe Color GetNearestColor(Color color)
{
uint argb = (uint)color.ToArgb();
CheckStatus(PInvokeGdiPlus.GdipGetNearestColor(NativeGraphics, &argb));
return Color.FromArgb((int)argb);
}
public unsafe void DrawLine(Pen pen, float x1, float y1, float x2, float y2)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
CheckErrorStatus(PInvokeGdiPlus.GdipDrawLine(NativeGraphics, pen.NativePen, x1, y1, x2, y2));
GC.KeepAlive(pen);
}
public void DrawBeziers(Pen pen, params PointF[] points)
{
DrawBeziers(pen, points.OrThrowIfNull("points").AsSpan());
}
[NullableContext(0)]
public unsafe void DrawBeziers([Nullable(1)] Pen pen, [ParamCollection] [ScopedRef] ReadOnlySpan<PointF> points)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (PointF* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawBeziers(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points2, points.Length));
}
GC.KeepAlive(pen);
}
public void DrawBeziers(Pen pen, params Point[] points)
{
DrawBeziers(pen, points.OrThrowIfNull("points").AsSpan());
}
[NullableContext(0)]
public unsafe void DrawBeziers([Nullable(1)] Pen pen, [ParamCollection] [ScopedRef] ReadOnlySpan<Point> points)
{
ArgumentNullException.ThrowIfNull(pen, "pen");
fixed (Point* points2 = &points.GetPinnableReference()) {
CheckErrorStatus(PInvokeGdiPlus.GdipDrawBeziersI(NativeGraphics, pen.NativePen, (global::Windows.Win32.Graphics.GdiPlus.Point*)points2, points.Length));
}
GC.KeepAlive(pen);
}
public unsafe void FillPath(Brush brush, GraphicsPath path)
{
ArgumentNullException.ThrowIfNull(brush, "brush");
ArgumentNullException.ThrowIfNull(path, "path");
CheckErrorStatus(PInvokeGdiPlus.GdipFillPath(NativeGraphics, brush.NativeBrush, path._nativePath));
GC.KeepAlive(brush);
GC.KeepAlive(path);
}
public unsafe void FillRegion(Brush brush, Region region)
{
ArgumentNullException.ThrowIfNull(brush, "brush");
ArgumentNullException.ThrowIfNull(region, "region");
CheckErrorStatus(PInvokeGdiPlus.GdipFillRegion(NativeGraphics, brush.NativeBrush, region.NativeRegion));
GC.KeepAlive(brush);
GC.KeepAlive(region);
}
public void DrawIcon(Icon icon, int x, int y)
{
ArgumentNullException.ThrowIfNull(icon, "icon");
if (_backingImage != null)
DrawImage(icon.ToBitmap(), x, y);
else
icon.Draw(this, x, y);
}
public void DrawIcon(Icon icon, Rectangle targetRect)
{
ArgumentNullException.ThrowIfNull(icon, "icon");
if (_backingImage != null)
DrawImage(icon.ToBitmap(), targetRect);
else
icon.Draw(this, targetRect);
}
public void DrawIconUnstretched(Icon icon, Rectangle targetRect)
{
ArgumentNullException.ThrowIfNull(icon, "icon");
if (_backingImage != null)
DrawImageUnscaled(icon.ToBitmap(), targetRect);
else
icon.DrawUnstretched(this, targetRect);
}
public unsafe void EnumerateMetafile(Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData, [Nullable(2)] ImageAttributes imageAttr)
{
using (EnumerateMetafileDataAdapter enumerateMetafileDataAdapter = new EnumerateMetafileDataAdapter(callback)) {
PInvokeGdiPlus.GdipEnumerateMetafileDestPoint(NativeGraphics, metafile.Pointer(), (global::Windows.Win32.Graphics.GdiPlus.PointF*)(&destPoint), enumerateMetafileDataAdapter.NativeCallback, (void*)(long)callbackData, imageAttr.Pointer()).ThrowIfFailed();
GC.KeepAlive(imageAttr);
GC.KeepAlive(metafile);
GC.KeepAlive(this);
}
}
public void EnumerateMetafile(Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData, [Nullable(2)] ImageAttributes imageAttr)
{
EnumerateMetafile(metafile, (PointF)destPoint, callback, callbackData, imageAttr);
}
public unsafe void EnumerateMetafile(Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData, [Nullable(2)] ImageAttributes imageAttr)
{
using (EnumerateMetafileDataAdapter enumerateMetafileDataAdapter = new EnumerateMetafileDataAdapter(callback)) {
PInvokeGdiPlus.GdipEnumerateMetafileDestRect(NativeGraphics, metafile.Pointer(), (RectF*)(&destRect), enumerateMetafileDataAdapter.NativeCallback, (void*)(long)callbackData, imageAttr.Pointer()).ThrowIfFailed();
GC.KeepAlive(imageAttr);
GC.KeepAlive(metafile);
GC.KeepAlive(this);
}
}
public void EnumerateMetafile(Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData, [Nullable(2)] ImageAttributes imageAttr)
{
EnumerateMetafile(metafile, (RectangleF)destRect, callback, callbackData, imageAttr);
}
public unsafe void EnumerateMetafile(Metafile metafile, PointF[] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, [Nullable(2)] ImageAttributes imageAttr)
{
ArgumentNullException.ThrowIfNull(destPoints, "destPoints");
if (destPoints.Length != 3)
throw new ArgumentException(System.SR.GdiplusDestPointsInvalidParallelogram);
fixed (PointF* destPoints2 = destPoints) {
using (EnumerateMetafileDataAdapter enumerateMetafileDataAdapter = new EnumerateMetafileDataAdapter(callback)) {
PInvokeGdiPlus.GdipEnumerateMetafileDestPoints(NativeGraphics, metafile.Pointer(), (global::Windows.Win32.Graphics.GdiPlus.PointF*)destPoints2, destPoints.Length, enumerateMetafileDataAdapter.NativeCallback, (void*)(long)callbackData, imageAttr.Pointer()).ThrowIfFailed();
GC.KeepAlive(imageAttr);
GC.KeepAlive(metafile);
GC.KeepAlive(this);
}
}
}
public unsafe void EnumerateMetafile(Metafile metafile, Point[] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, [Nullable(2)] ImageAttributes imageAttr)
{
ArgumentNullException.ThrowIfNull(destPoints, "destPoints");
if (destPoints.Length != 3)
throw new ArgumentException(System.SR.GdiplusDestPointsInvalidParallelogram);
fixed (Point* destPoints2 = destPoints) {
using (EnumerateMetafileDataAdapter enumerateMetafileDataAdapter = new EnumerateMetafileDataAdapter(callback)) {
PInvokeGdiPlus.GdipEnumerateMetafileDestPointsI(NativeGraphics, metafile.Pointer(), (global::Windows.Win32.Graphics.GdiPlus.Point*)destPoints2, destPoints.Length, enumerateMetafileDataAdapter.NativeCallback, (void*)(long)callbackData, imageAttr.Pointer()).ThrowIfFailed();
GC.KeepAlive(imageAttr);
GC.KeepAlive(metafile);
GC.KeepAlive(this);
}
}
}
public unsafe void EnumerateMetafile(Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, [Nullable(2)] ImageAttributes imageAttr)
{
using (EnumerateMetafileDataAdapter enumerateMetafileDataAdapter = new EnumerateMetafileDataAdapter(callback)) {
PInvokeGdiPlus.GdipEnumerateMetafileSrcRectDestPoint(NativeGraphics, metafile.Pointer(), (global::Windows.Win32.Graphics.GdiPlus.PointF*)(&destPoint), (RectF*)(&srcRect), (Unit)unit, enumerateMetafileDataAdapter.NativeCallback, (void*)(long)callbackData, imageAttr.Pointer()).ThrowIfFailed();
GC.KeepAlive(imageAttr);
GC.KeepAlive(metafile);
GC.KeepAlive(this);
}
}
public void EnumerateMetafile(Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, [Nullable(2)] ImageAttributes imageAttr)
{
EnumerateMetafile(metafile, (PointF)destPoint, (RectangleF)srcRect, unit, callback, callbackData, imageAttr);
}
public unsafe void EnumerateMetafile(Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, [Nullable(2)] ImageAttributes imageAttr)
{
using (EnumerateMetafileDataAdapter enumerateMetafileDataAdapter = new EnumerateMetafileDataAdapter(callback)) {
PInvokeGdiPlus.GdipEnumerateMetafileSrcRectDestRect(NativeGraphics, metafile.Pointer(), (RectF*)(&destRect), (RectF*)(&srcRect), (Unit)unit, enumerateMetafileDataAdapter.NativeCallback, (void*)(long)callbackData, imageAttr.Pointer()).ThrowIfFailed();
GC.KeepAlive(imageAttr);
GC.KeepAlive(metafile);
GC.KeepAlive(this);
}
}
public void EnumerateMetafile(Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, [Nullable(2)] ImageAttributes imageAttr)
{
EnumerateMetafile(metafile, (RectangleF)destRect, (RectangleF)srcRect, unit, callback, callbackData, imageAttr);
}
public unsafe void EnumerateMetafile(Metafile metafile, PointF[] destPoints, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, [Nullable(2)] ImageAttributes imageAttr)
{
ArgumentNullException.ThrowIfNull(destPoints, "destPoints");
if (destPoints.Length != 3)
throw new ArgumentException(System.SR.GdiplusDestPointsInvalidParallelogram);
fixed (PointF* destPoints2 = destPoints) {
using (EnumerateMetafileDataAdapter enumerateMetafileDataAdapter = new EnumerateMetafileDataAdapter(callback)) {
PInvokeGdiPlus.GdipEnumerateMetafileSrcRectDestPoints(NativeGraphics, metafile.Pointer(), (global::Windows.Win32.Graphics.GdiPlus.PointF*)destPoints2, destPoints.Length, (RectF*)(&srcRect), (Unit)unit, enumerateMetafileDataAdapter.NativeCallback, (void*)(long)callbackData, imageAttr.Pointer()).ThrowIfFailed();
GC.KeepAlive(imageAttr);
GC.KeepAlive(metafile);
GC.KeepAlive(this);
}
}
}
public unsafe void EnumerateMetafile(Metafile metafile, Point[] destPoints, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, [Nullable(2)] ImageAttributes imageAttr)
{
ArgumentNullException.ThrowIfNull(destPoints, "destPoints");
if (destPoints.Length != 3)
throw new ArgumentException(System.SR.GdiplusDestPointsInvalidParallelogram);
fixed (Point* destPoints2 = destPoints) {
using (EnumerateMetafileDataAdapter enumerateMetafileDataAdapter = new EnumerateMetafileDataAdapter(callback)) {
PInvokeGdiPlus.GdipEnumerateMetafileSrcRectDestPointsI(NativeGraphics, metafile.Pointer(), (global::Windows.Win32.Graphics.GdiPlus.Point*)destPoints2, destPoints.Length, (Rect*)(&srcRect), (Unit)unit, enumerateMetafileDataAdapter.NativeCallback, (void*)(long)callbackData, imageAttr.Pointer()).ThrowIfFailed();
GC.KeepAlive(imageAttr);
GC.KeepAlive(metafile);
GC.KeepAlive(this);
}
}
}
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Use the Graphics.GetContextInfo overloads that accept arguments for better performance and fewer allocations.", DiagnosticId = "SYSLIB0016", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[SupportedOSPlatform("windows")]
public object GetContextInfo()
{
GetContextInfo(out Matrix3x2 cumulativeTransform, true, out Region cumulativeClip);
return new object[2] {
cumulativeClip ?? new Region(),
new System.Drawing.Drawing2D.Matrix(cumulativeTransform)
};
}
[NullableContext(2)]
private void GetContextInfo(out Matrix3x2 cumulativeTransform, bool calculateClip, out Region cumulativeClip)
{
cumulativeClip = (calculateClip ? GetRegionIfNotInfinite() : null);
cumulativeTransform = TransformElements;
Vector2 vector = default(Vector2);
Vector2 vector2 = default(Vector2);
GraphicsContext graphicsContext = _previousContext;
if (!cumulativeTransform.IsIdentity)
vector = cumulativeTransform.Translation;
while (graphicsContext != null) {
if (!graphicsContext.TransformOffset.IsEmpty())
ref cumulativeTransform.Translate(graphicsContext.TransformOffset);
if (!vector.IsEmpty()) {
cumulativeClip?.Translate(vector.X, vector.Y);
vector2.X += vector.X;
vector2.Y += vector.Y;
}
if (calculateClip && graphicsContext.Clip != null) {
if (cumulativeClip == null)
cumulativeClip = graphicsContext.Clip;
else
cumulativeClip.Intersect(graphicsContext.Clip);
}
vector = graphicsContext.TransformOffset;
do {
graphicsContext = graphicsContext.Previous;
} while (graphicsContext != null && graphicsContext.Next.IsCumulative && graphicsContext.IsCumulative);
}
if (!vector2.IsEmpty())
cumulativeClip?.Translate(0 - vector2.X, 0 - vector2.Y);
}
[NullableContext(0)]
(HDC hdc, int saveState) IGraphicsContextInfo.GetHdc(ApplyGraphicsProperties apply, bool alwaysSaveState)
{
bool flag = apply.HasFlag(ApplyGraphicsProperties.TranslateTransform);
bool flag2 = apply.HasFlag(ApplyGraphicsProperties.Clipping);
int item = 0;
HDC hDC = HDC.Null;
Region clip = null;
PointF offset = default(PointF);
if (flag2)
GetContextInfo(out offset, out clip);
else if (flag) {
GetContextInfo(out offset);
}
using (clip) {
flag = (flag && !offset.IsEmpty);
flag2 = (clip != null);
RegionScope regionScope = flag2 ? clip.GetRegionScope(this) : default(RegionScope);
try {
flag2 = (flag2 && !regionScope.Region.IsNull);
hDC = (HDC)GetHdc();
if (alwaysSaveState | flag2 | flag)
item = PInvokeCore.SaveDC(hDC);
if (flag2) {
RegionScope regionScope2 = new RegionScope(hDC);
try {
if (!regionScope2.IsNull && PInvokeCore.CombineRgn(regionScope, regionScope2, regionScope, RGN_COMBINE_MODE.RGN_AND) == GDI_REGION_TYPE.RGN_ERROR)
throw new Win32Exception();
if (PInvokeCore.SelectClipRgn(hDC, regionScope) == GDI_REGION_TYPE.RGN_ERROR)
throw new Win32Exception();
} finally {
regionScope2.Dispose();
}
}
if (flag)
PInvokeCore.OffsetViewportOrgEx(hDC, (int)offset.X, (int)offset.Y, null);
} finally {
regionScope.Dispose();
}
}
return (hDC, item);
}
[EditorBrowsable(EditorBrowsableState.Never)]
[SupportedOSPlatform("windows")]
public void GetContextInfo(out PointF offset)
{
GetContextInfo(out Matrix3x2 cumulativeTransform, false, out Region _);
Vector2 translation = cumulativeTransform.Translation;
offset = new PointF(translation.X, translation.Y);
}
[NullableContext(2)]
[EditorBrowsable(EditorBrowsableState.Never)]
[SupportedOSPlatform("windows")]
public void GetContextInfo(out PointF offset, out Region clip)
{
GetContextInfo(out Matrix3x2 cumulativeTransform, true, out clip);
Vector2 translation = cumulativeTransform.Translation;
offset = new PointF(translation.X, translation.Y);
}
private void PushContext(GraphicsContext context)
{
if (_previousContext != null) {
context.Previous = _previousContext;
_previousContext.Next = context;
}
_previousContext = context;
}
private void PopContext(int currentContextState)
{
GraphicsContext graphicsContext = _previousContext;
while (true) {
if (graphicsContext == null)
return;
if (graphicsContext.State == currentContextState)
break;
graphicsContext = graphicsContext.Previous;
}
_previousContext = graphicsContext.Previous;
graphicsContext.Dispose();
}
public unsafe GraphicsState Save()
{
GraphicsContext graphicsContext = new GraphicsContext(this);
uint num = default(uint);
Status status = PInvokeGdiPlus.GdipSaveGraphics(NativeGraphics, &num);
GC.KeepAlive(this);
if (status != 0) {
graphicsContext.Dispose();
throw Gdip.StatusException(status);
}
graphicsContext.State = (int)num;
graphicsContext.IsCumulative = true;
PushContext(graphicsContext);
return new GraphicsState((int)num);
}
public unsafe void Restore(GraphicsState gstate)
{
CheckStatus(PInvokeGdiPlus.GdipRestoreGraphics(NativeGraphics, (uint)gstate._nativeState));
PopContext(gstate._nativeState);
}
public unsafe GraphicsContainer BeginContainer(RectangleF dstrect, RectangleF srcrect, GraphicsUnit unit)
{
GraphicsContext graphicsContext = new GraphicsContext(this);
uint num = default(uint);
Status status = PInvokeGdiPlus.GdipBeginContainer(NativeGraphics, (RectF*)(&dstrect), (RectF*)(&srcrect), (Unit)unit, &num);
GC.KeepAlive(this);
if (status != 0) {
graphicsContext.Dispose();
throw Gdip.StatusException(status);
}
graphicsContext.State = (int)num;
PushContext(graphicsContext);
return new GraphicsContainer((int)num);
}
public unsafe GraphicsContainer BeginContainer()
{
GraphicsContext graphicsContext = new GraphicsContext(this);
uint num = default(uint);
Status status = PInvokeGdiPlus.GdipBeginContainer2(NativeGraphics, &num);
GC.KeepAlive(this);
if (status != 0) {
graphicsContext.Dispose();
throw Gdip.StatusException(status);
}
graphicsContext.State = (int)num;
PushContext(graphicsContext);
return new GraphicsContainer((int)num);
}
public unsafe void EndContainer(GraphicsContainer container)
{
ArgumentNullException.ThrowIfNull(container, "container");
CheckStatus(PInvokeGdiPlus.GdipEndContainer(NativeGraphics, (uint)container._nativeGraphicsContainer));
PopContext(container._nativeGraphicsContainer);
}
public GraphicsContainer BeginContainer(Rectangle dstrect, Rectangle srcrect, GraphicsUnit unit)
{
return BeginContainer((RectangleF)dstrect, (RectangleF)srcrect, unit);
}
public unsafe void AddMetafileComment(byte[] data)
{
ArgumentNullException.ThrowIfNull(data, "data");
fixed (byte* data2 = data) {
CheckStatus(PInvokeGdiPlus.GdipComment(NativeGraphics, (uint)data.Length, data2));
}
}
public static IntPtr GetHalftonePalette()
{
if (s_halftonePalette.IsNull) {
Lock.Scope scope = s_syncObject.EnterScope();
try {
if (s_halftonePalette.IsNull) {
GdiPlusInitialization.EnsureInitialized();
s_halftonePalette = PInvokeGdiPlus.GdipCreateHalftonePalette();
}
} finally {
scope.Dispose();
}
}
return s_halftonePalette;
}
private void CheckErrorStatus(Status status)
{
bool flag;
switch (status) {
case Status.Ok:
return;
case Status.GenericError:
case Status.Win32Error:
flag = true;
break;
default:
flag = false;
break;
}
if (flag) {
WIN32_ERROR lastWin32Error = (WIN32_ERROR)Marshal.GetLastWin32Error();
if (lastWin32Error == WIN32_ERROR.ERROR_ACCESS_DENIED || lastWin32Error == WIN32_ERROR.ERROR_PROC_NOT_FOUND || ((PInvokeCore.GetSystemMetrics(SYSTEM_METRICS_INDEX.SM_REMOTESESSION) & 1) != 0 && lastWin32Error == WIN32_ERROR.NO_ERROR))
return;
}
GC.KeepAlive(this);
throw Gdip.StatusException(status);
}
public unsafe void DrawCachedBitmap(CachedBitmap cachedBitmap, int x, int y)
{
ArgumentNullException.ThrowIfNull(cachedBitmap, "cachedBitmap");
CheckStatus(PInvokeGdiPlus.GdipDrawCachedBitmap(NativeGraphics, (GpCachedBitmap*)(long)cachedBitmap.Handle, x, y));
GC.KeepAlive(cachedBitmap);
}
public void DrawImage(Image image, Effect effect)
{
DrawImage(image, effect, default(RectangleF), null, GraphicsUnit.Pixel, null);
}
public unsafe void DrawImage(Image image, Effect effect, RectangleF srcRect = default(RectangleF), [Nullable(2)] System.Drawing.Drawing2D.Matrix transform = null, GraphicsUnit srcUnit = GraphicsUnit.Pixel, [Nullable(2)] ImageAttributes imageAttr = null)
{
PInvokeGdiPlus.GdipDrawImageFX(NativeGraphics, image.Pointer(), (RectF*)(long)(srcRect.IsEmpty ? ((IntPtr)(void*)null) : ((IntPtr)(&srcRect))), transform.Pointer(), effect.Pointer(), imageAttr.Pointer(), (Unit)srcUnit).ThrowIfFailed();
GC.KeepAlive(effect);
GC.KeepAlive(imageAttr);
GC.KeepAlive(image);
GC.KeepAlive(this);
}
private void CheckStatus(Status status)
{
status.ThrowIfFailed();
GC.KeepAlive(this);
}
}
}