public T LoadBitmapFromStream <T>(Stream stream, CreateBitmapDelegate <T> create) { using (GdkPixBufBitmapSource source = LoadSourceFromStream(stream)) { return(create(source)); } }
public INativeImage LoadImageFromStream(Stream stream) { using (GdkPixBufBitmapSource source = LoadSourceFromStream(stream)) { X11Image disposableImage = X11Image.Create(display, visual, rootWindow, source.Width, source.Height); try { source.CopyToImage(disposableImage); X11Image image = disposableImage; disposableImage = null; return(image); } finally { disposableImage?.Dispose(); } } }
private GdkPixBufBitmapSource LoadSourceFromGdkStream(IntPtr gdkStream) { IntPtr pixbuf = LibGdkPixBuf.gdk_pixbuf_new_from_stream(gdkStream, IntPtr.Zero, out IntPtr errorPtr); try { if (pixbuf == IntPtr.Zero) { string gdkErrorMessage; if (errorPtr != IntPtr.Zero) { GError error = Marshal.PtrToStructure <GError>(errorPtr); gdkErrorMessage = error.message; } else { gdkErrorMessage = "Unknown error."; } throw new IOException($"{nameof(LibGdkPixBuf.gdk_pixbuf_new_from_stream)} error: {gdkErrorMessage}"); } var source = GdkPixBufBitmapSource.Create(pixbuf); pixbuf = IntPtr.Zero; return(source); } finally { if (pixbuf != IntPtr.Zero) { LibGdkPixBuf.g_object_unref(pixbuf); } if (errorPtr != IntPtr.Zero) { LibGdkPixBuf.g_error_free(errorPtr); } } }