<PackageReference Include="System.Drawing.Common" Version="9.0.8" />

GpBitmapExtensions

static class GpBitmapExtensions
using System; using System.Drawing; using System.Runtime.CompilerServices; using Windows.Win32.Foundation; using Windows.Win32.Graphics.Gdi; namespace Windows.Win32.Graphics.GdiPlus { [NullableContext(1)] [Nullable(0)] internal static class GpBitmapExtensions { public unsafe static void LockBits(this IPointer<GpBitmap> bitmap, Rectangle rect, ImageLockMode flags, PixelFormat format, ref BitmapData data) { PInvokeCore.GdipBitmapLockBits(bitmap.GetPointer(), (Rect*)(long)(rect.IsEmpty ? ((IntPtr)(void*)null) : ((IntPtr)(&rect))), (uint)flags, (int)format, (BitmapData*)Unsafe.AsPointer(ref data)).ThrowIfFailed(); GC.KeepAlive(bitmap); } public unsafe static void UnlockBits(this IPointer<GpBitmap> bitmap, ref BitmapData data) { PInvokeCore.GdipBitmapUnlockBits(bitmap.GetPointer(), (BitmapData*)Unsafe.AsPointer(ref data)).ThrowIfFailed(); GC.KeepAlive(bitmap); } public static HBITMAP GetHBITMAP(this IPointer<GpBitmap> bitmap) { return bitmap.GetHBITMAP(Color.LightGray); } public unsafe static HBITMAP GetHBITMAP(this IPointer<GpBitmap> bitmap, Color background) { HBITMAP result = default(HBITMAP); PInvokeCore.GdipCreateHBITMAPFromBitmap(bitmap.GetPointer(), &result, (uint)ColorTranslator.ToWin32(background)).ThrowIfFailed(); GC.KeepAlive(bitmap); return result; } } }