public static Image Load(Stream stream) { if (stream != null) { unsafe { IntPtr pNativeImage = IntPtr.Zero; var wrapper = new gdStreamWrapper(stream); pNativeImage = DLLImports.gdImageCreateFromPngCtx(ref wrapper.IOCallbacks); DLLImports.gdImageStruct *pStruct = (DLLImports.gdImageStruct *)pNativeImage; Image toRet = Image.Create(pStruct->sx, pStruct->sx); DLLImports.gdImageDestroy(toRet.gdImageStructPtr); toRet.gdImageStructPtr = pNativeImage; return(toRet); } } else { throw new InvalidOperationException(SR.NullStreamReferenced); } }
/* Release */ public void ReleaseStruct() { DLLImports.gdImageDestroy(gdImageStructPtr); }