public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string description) { if (stream == null) { throw new NullReferenceException("stream"); } Status status = Status.NotImplemented; 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. GDIPlus.GdiPlusStreamHelper sh = new GDIPlus.GdiPlusStreamHelper(stream, false); status = GDIPlus.GdipRecordMetafileFromDelegate_linux(sh.GetHeaderDelegate, sh.GetBytesDelegate, sh.PutBytesDelegate, sh.SeekDelegate, sh.CloseDelegate, sh.SizeDelegate, referenceHdc, type, ref frameRect, frameUnit, description, out nativeObject); } else { status = GDIPlus.GdipRecordMetafileStream(new ComIStreamWrapper(stream), referenceHdc, type, ref frameRect, frameUnit, description, out nativeObject); } GDIPlus.CheckStatus(status); }
public static MetafileHeader GetMetafileHeader(Stream stream) { if (stream == null) { throw new NullReferenceException("stream"); } IntPtr header = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MetafileHeader))); try { 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. GDIPlus.GdiPlusStreamHelper sh = new GDIPlus.GdiPlusStreamHelper(stream, false); status = GDIPlus.GdipGetMetafileHeaderFromDelegate_linux(sh.GetHeaderDelegate, sh.GetBytesDelegate, sh.PutBytesDelegate, sh.SeekDelegate, sh.CloseDelegate, sh.SizeDelegate, header); } else { status = GDIPlus.GdipGetMetafileHeaderFromStream(new ComIStreamWrapper(stream), header); } GDIPlus.CheckStatus(status); return(new MetafileHeader(header)); } finally { Marshal.FreeHGlobal(header); } }
internal static IntPtr InitFromStream(Stream stream) { if (stream == null) { throw new ArgumentException("stream"); } IntPtr imagePtr; Status st; // Seeking required if (!stream.CanSeek) { byte[] buffer = new byte[256]; int index = 0; int count; do { if (buffer.Length < index + 256) { byte[] newBuffer = new byte[buffer.Length * 2]; Array.Copy(buffer, newBuffer, buffer.Length); buffer = newBuffer; } count = stream.Read(buffer, index, 256); index += count; }while (count != 0); stream = new MemoryStream(buffer, 0, index); } if (GDIPlus.RunningOnUnix()) { // Unix, 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. GDIPlus.GdiPlusStreamHelper sh = new GDIPlus.GdiPlusStreamHelper(stream, true); st = GDIPlus.GdipLoadImageFromDelegate_linux(sh.GetHeaderDelegate, sh.GetBytesDelegate, sh.PutBytesDelegate, sh.SeekDelegate, sh.CloseDelegate, sh.SizeDelegate, out imagePtr); } else { st = GDIPlus.GdipLoadImageFromStream(new ComIStreamWrapper(stream), out imagePtr); } return(st == Status.Ok ? imagePtr : IntPtr.Zero); }
public Metafile (Stream stream) { if (stream == null) throw new ArgumentException ("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. GDIPlus.GdiPlusStreamHelper sh = new GDIPlus.GdiPlusStreamHelper (stream, false); status = GDIPlus.GdipCreateMetafileFromDelegate_linux (sh.GetHeaderDelegate, sh.GetBytesDelegate, sh.PutBytesDelegate, sh.SeekDelegate, sh.CloseDelegate, sh.SizeDelegate, out nativeObject); } else { status = GDIPlus.GdipCreateMetafileFromStream (new ComIStreamWrapper (stream), out nativeObject); } GDIPlus.CheckStatus (status); }
public void Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) { Status st; IntPtr nativeEncoderParams; Guid guid = encoder.Clsid; if (encoderParams == null) { nativeEncoderParams = IntPtr.Zero; } else { nativeEncoderParams = encoderParams.ToNativePtr(); } try { if (GDIPlus.RunningOnUnix()) { GDIPlus.GdiPlusStreamHelper sh = new GDIPlus.GdiPlusStreamHelper(stream, false); st = GDIPlus.GdipSaveImageToDelegate_linux(nativeObject, sh.GetBytesDelegate, sh.PutBytesDelegate, sh.SeekDelegate, sh.CloseDelegate, sh.SizeDelegate, ref guid, nativeEncoderParams); } else { st = GDIPlus.GdipSaveImageToStream(new HandleRef(this, nativeObject), new ComIStreamWrapper(stream), ref guid, new HandleRef(encoderParams, nativeEncoderParams)); } } finally { if (nativeEncoderParams != IntPtr.Zero) { Marshal.FreeHGlobal(nativeEncoderParams); } } GDIPlus.CheckStatus(st); }
public Metafile(Stream stream) { if (stream == null) { throw new ArgumentException("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. GDIPlus.GdiPlusStreamHelper sh = new GDIPlus.GdiPlusStreamHelper(stream, false); status = GDIPlus.GdipCreateMetafileFromDelegate_linux(sh.GetHeaderDelegate, sh.GetBytesDelegate, sh.PutBytesDelegate, sh.SeekDelegate, sh.CloseDelegate, sh.SizeDelegate, out nativeObject); } else { status = GDIPlus.GdipCreateMetafileFromStream(new ComIStreamWrapper(stream), out nativeObject); } GDIPlus.CheckStatus(status); }
public static MetafileHeader GetMetafileHeader (Stream stream) { if (stream == null) throw new NullReferenceException ("stream"); IntPtr header = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (MetafileHeader))); try { 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. GDIPlus.GdiPlusStreamHelper sh = new GDIPlus.GdiPlusStreamHelper (stream, false); status = GDIPlus.GdipGetMetafileHeaderFromDelegate_linux (sh.GetHeaderDelegate, sh.GetBytesDelegate, sh.PutBytesDelegate, sh.SeekDelegate, sh.CloseDelegate, sh.SizeDelegate, header); } else { status = GDIPlus.GdipGetMetafileHeaderFromStream (new ComIStreamWrapper (stream), header); } GDIPlus.CheckStatus (status); return new MetafileHeader (header); } finally { Marshal.FreeHGlobal (header); } }
public Metafile (Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string description) { if (stream == null) throw new NullReferenceException ("stream"); Status status = Status.NotImplemented; 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. GDIPlus.GdiPlusStreamHelper sh = new GDIPlus.GdiPlusStreamHelper (stream, false); status = GDIPlus.GdipRecordMetafileFromDelegate_linux (sh.GetHeaderDelegate, sh.GetBytesDelegate, sh.PutBytesDelegate, sh.SeekDelegate, sh.CloseDelegate, sh.SizeDelegate, referenceHdc, type, ref frameRect, frameUnit, description, out nativeObject); } else { status = GDIPlus.GdipRecordMetafileStream (new ComIStreamWrapper (stream), referenceHdc, type, ref frameRect, frameUnit, description, out nativeObject); } GDIPlus.CheckStatus (status); }