public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string description) { if (stream == null) { throw new NullReferenceException(nameof(stream)); } // With libgdiplus we use a custom API for this, because there's no easy way // to get the Stream down to libgdiplus. So, we wrap the stream with a set of delegates. GdiPlusStreamHelper sh = new GdiPlusStreamHelper(stream, false); int status = Gdip.GdipRecordMetafileFromDelegate_linux(sh.GetHeaderDelegate, sh.GetBytesDelegate, sh.PutBytesDelegate, sh.SeekDelegate, sh.CloseDelegate, sh.SizeDelegate, referenceHdc, type, ref frameRect, frameUnit, description, out nativeImage); // Since we're just passing to native code the delegates inside the wrapper, we need to keep sh alive // to avoid the object being collected and therefore the delegates would be collected as well. GC.KeepAlive(sh); Gdip.CheckStatus(status); }
public Metafile(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } Status status; if (GDIPlus.RunningOnUnix()) { // With libgdiplus we use a custom API for this, because there's no easy way // to get the Stream down to libgdiplus. So, we wrap the stream with a set of delegates. GdiPlusStreamHelper sh = new GdiPlusStreamHelper(stream, false); status = SafeNativeMethods.Gdip.GdipCreateMetafileFromDelegate_linux(sh.GetHeaderDelegate, sh.GetBytesDelegate, sh.PutBytesDelegate, sh.SeekDelegate, sh.CloseDelegate, sh.SizeDelegate, out nativeObject); } else { status = SafeNativeMethods.Gdip.GdipCreateMetafileFromStream(new ComIStreamWrapper(stream), out nativeObject); } SafeNativeMethods.Gdip.CheckStatus(status); }