GpImageExtensions
using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using Windows.Win32.Foundation;
using Windows.Win32.Graphics.Gdi;
using Windows.Win32.System.Ole;
namespace Windows.Win32.Graphics.GdiPlus
{
[NullableContext(1)]
[Nullable(0)]
internal static class GpImageExtensions
{
[SkipLocalsInit]
internal unsafe static RectangleF GetImageBounds(this IPointer<GpImage> image)
{
RectangleF result;
Unit unit;
PInvokeGdiPlus.GdipGetImageBounds(image.GetPointer(), (RectF*)(&result), &unit).ThrowIfFailed();
GC.KeepAlive(image);
return result;
}
[SkipLocalsInit]
internal unsafe static PixelFormat GetPixelFormat(this IPointer<GpImage> image)
{
int result;
Status num = PInvokeGdiPlus.GdipGetImagePixelFormat(image.GetPointer(), &result);
GC.KeepAlive(image);
if (num != 0)
return PixelFormat.Undefined;
return (PixelFormat)result;
}
public static PICTDESC CreatePICTDESC(this IPointer<GpImage> image)
{
IPointer<GpBitmap> pointer = image as IPointer<GpBitmap>;
if (pointer != null)
return pointer.CreatePICTDESC(default(HPALETTE));
IPointer<GpMetafile> pointer2 = image as IPointer<GpMetafile>;
if (pointer2 == null)
throw new InvalidOperationException();
return pointer2.CreatePICTDESC();
}
public static IPictureDisp.Interface CreateIPictureDispRCW(this IPointer<GpImage> image)
{
ComScope<IPictureDisp> comScope = image.CreateIPictureDisp();
try {
return (IPictureDisp.Interface)ComHelpers.GetObjectForIUnknown(comScope);
} finally {
comScope.Dispose();
}
}
[NullableContext(0)]
public unsafe static ComScope<IPictureDisp> CreateIPictureDisp([Nullable(1)] this IPointer<GpImage> image)
{
PICTDESC pICTDESC = image.CreatePICTDESC();
ComScope<IPictureDisp> scope = new ComScope<IPictureDisp>(null);
PInvokeCore.OleCreatePictureIndirect(&pICTDESC, IID.Get<IPictureDisp>(), true, (void**)ref scope).ThrowOnFailure((IntPtr)0);
return scope;
}
public static object CreateIPictureRCW(this IPointer<GpImage> image)
{
ComScope<IPicture> comScope = image.CreateIPicture();
try {
return (IPicture.Interface)ComHelpers.GetObjectForIUnknown(comScope);
} finally {
comScope.Dispose();
}
}
[NullableContext(0)]
public unsafe static ComScope<IPicture> CreateIPicture([Nullable(1)] this IPointer<GpImage> image)
{
PICTDESC pICTDESC = image.CreatePICTDESC();
ComScope<IPicture> scope = new ComScope<IPicture>(null);
PInvokeCore.OleCreatePictureIndirect(&pICTDESC, IID.Get<IPicture>(), true, (void**)ref scope).ThrowOnFailure((IntPtr)0);
return scope;
}
}
}