private GdkPixBufBitmapSource LoadSourceFromMemory(IntPtr sourceBuffer, int sourceBufferSize) { IntPtr gdkStream = LibGdkPixBuf.g_memory_input_stream_new_from_data(sourceBuffer, sourceBufferSize, IntPtr.Zero); try { return(LoadSourceFromGdkStream(gdkStream)); } finally { LibGdkPixBuf.g_object_unref(gdkStream); } }
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); } } }
public void Dispose() { LibGdkPixBuf.g_object_unref(pixbuf); }