Effect
Base class for all effects.
using System.Runtime.CompilerServices;
using Windows.Win32;
using Windows.Win32.Graphics.GdiPlus;
namespace System.Drawing.Imaging.Effects
{
public abstract class Effect : IDisposable
{
private unsafe CGpEffect* _nativeEffect;
internal unsafe CGpEffect* NativeEffect => _nativeEffect;
private protected unsafe Effect(Guid guid)
{
CGpEffect* nativeEffect = default(CGpEffect*);
PInvokeGdiPlus.GdipCreateEffect(guid, &nativeEffect).ThrowIfFailed();
_nativeEffect = nativeEffect;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private protected unsafe void SetParameters<[IsUnmanaged] T>(ref T parameters) where T : struct
{
fixed (T* params = ¶meters) {
PInvokeGdiPlus.GdipSetEffectParameters(NativeEffect, params, (uint)sizeof(T)).ThrowIfFailed();
GC.KeepAlive(this);
}
}
~Effect()
{
Dispose(false);
}
protected unsafe virtual void Dispose(bool disposing)
{
if (_nativeEffect != null) {
PInvokeGdiPlus.GdipDeleteEffect(_nativeEffect);
_nativeEffect = null;
}
}
}
}